December 10, 2008 at 10:55 am
I have a table in which i have 4 columns
order_type,order_source,date,center_id
now i have order_source as
internal,external,self
so what all i need is
in order source i need to display if internal then internal ,if external then external
if self then here comes the problem
then i need to join this table1 with lookuptable based on center_id and get the name from table 2 as order_source ....
can anyone help me out how to do that ...plz a bit urgent
Thanks,
Chinna
Its the Journey which gives you Happiness not the Destination-- Dan Millman
December 10, 2008 at 11:26 am
if self then here comes the problem
then i need to join this table1 with lookuptable based on center_id and get the name from table 2 as order_source ....
just join table 2 however you need to (you didn't specify enough information)
in your select, put
CASE when order_source = 'self' then (name of column from table 2)
else order_source
end as order_source
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
December 10, 2008 at 11:37 am
I will give you a couple of hints:
1) You need to JOIN the table in your query
2) You will need to use a CASE expression to return the appropriate data
If you want a better, tested response - review the article:
Best Practices: http://www.sqlservercentral.com/articles/Best+Practices/61537/
And - curious, by why is this so urgent?
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
December 10, 2008 at 12:59 pm
Sounds like the second table would be joined as a LEFT join, so look up OUTER JOINS in Books Online.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply