Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to shae a table /column with another table

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 table1
union all
select 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
Go to Top of Page

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!
Go to Top of Page

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
Go to Top of Page

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
Go to Top of Page

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 procedure
use a logic like below
http://dotnetkeeda.blogspot.in/2009/09/bcp-command-to-export-data-to-excel.html

then call stored procedure from sql agent job to execute it weekly



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

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
Go to Top of Page

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 utility
The options for you are
1. bcp
2. export import wizard
3. OPENROWSET

of these i've found bcp to be fastest in most cases.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Pasi
Posting Yak Master

166 Posts

Posted - 2014-02-12 : 11:39:36
Thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-13 : 07:50:11
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -