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
 Match value from column in T1 to T2?

Author  Topic 

PoppaNecktie
Starting Member

3 Posts

Posted - 2014-11-11 : 15:29:11
Hi Guys, I am very new to SQL queries. I was hoping someone could help me with a problem I’m having. Here’s the breakdown--

I have two tables in the same DB, one named “Client” one named “Case”.

-One column inside Client is “ClientID”, another is “ClientCode”.

-One column inside Case is “CaseID” and another is “ClientCode”, which corresponds to the ClientCode column in the previous table.

I need a file with output that looks like this CaseID+ClientID.

So, an example row from the “Client” table” could be ClientID = 123, ClientCode=999. An example row from the “Case table” could be CaseID=555, ClientCode=999. So, I need output of 555123 .

I hope I’ve explained this well enough. Thanks!!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-11-11 : 15:36:11
Does this produce the output you want?

select convert(varchar(20), CaseID) + convert(varchar(20), Client.ClientCode)
from Client
join Case on Client.ClientCode = Case.ClientCode

If so, you can export to a file using bcp, export wizard, SSIS, even SSMS can save output to a file.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

PoppaNecktie
Starting Member

3 Posts

Posted - 2014-11-11 : 15:55:19
This is great! Thank you very much. I realize that I left out one important part. I need this join to apply ONLY when column Status='Open' in Table Case . Sorry for leaving this out? Is there a quick way to add this condition?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-11-11 : 15:56:38
Just add a where clause to the query.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

PoppaNecktie
Starting Member

3 Posts

Posted - 2014-11-11 : 16:13:38
I think that did the trick. Thanks again!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-11-11 : 16:21:25


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -