Author |
Topic |
Pasi
Posting Yak Master
166 Posts |
Posted - 2014-02-10 : 11:49:38
|
HI,I have a table called person_payer and in this table there is a column called "Group_name" in which I need to share this filed with another table called "person" how can I share this 2 tables? I have to run a report that include this column field called "group_name" which does not exist in the "person" table? what is the best way to do this?Thanks a lot!Pasi |
|
xhostx
Constraint Violating Yak Guru
277 Posts |
Posted - 2014-02-10 : 11:59:14
|
Do a union or Union All. For the column that does NOT exist in the other table use NULL as "Group.."select col1 as name, col2 as group from table1union allselect cal1 as name, null as group from table2 Note: if you want distinct values use Union not Union all --------------------------Joins are what RDBMS's do for a living |
 |
|
Pasi
Posting Yak Master
166 Posts |
Posted - 2014-02-10 : 12:16:19
|
Thanks you Xhost! SO since I run this within application I am not sure how to set it up to union this? this table is pulled from our application or Crsytal report you think I can do this within application?Thanks! |
 |
|
xhostx
Constraint Violating Yak Guru
277 Posts |
Posted - 2014-02-10 : 13:22:41
|
Im not sure what you mean with the application, however, you can put in the SQL query (Union...) into a sqlcommand variable and execute.Can you be a little clear on what is you application is like?--------------------------Joins are what RDBMS's do for a living |
 |
|
Pasi
Posting Yak Master
166 Posts |
Posted - 2014-02-10 : 14:00:21
|
Ok that's fine may be I do it another way. So how can I save this query and run it automatically every week and output the query into excel? Thanks!Pasi |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-11 : 01:17:49
|
quote: Originally posted by Pasi Ok that's fine may be I do it another way. So how can I save this query and run it automatically every week and output the query into excel? Thanks!Pasi
use bcp for that inside a stored procedureuse a logic like belowhttp://dotnetkeeda.blogspot.in/2009/09/bcp-command-to-export-data-to-excel.htmlthen call stored procedure from sql agent job to execute it weekly------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
Pasi
Posting Yak Master
166 Posts |
Posted - 2014-02-11 : 10:59:34
|
Thanks Visakh! what is BCP and is there an easier way to do this? Just wondering?Pasi |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-11 : 23:33:25
|
quote: Originally posted by Pasi Thanks Visakh! what is BCP and is there an easier way to do this? Just wondering?Pasi
bcp is bulk copy command line utilityThe options for you are1. bcp2. export import wizard3. OPENROWSETof these i've found bcp to be fastest in most cases.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
Pasi
Posting Yak Master
166 Posts |
Posted - 2014-02-12 : 11:39:36
|
Thanks! |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-13 : 07:50:11
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|