January 29, 2014 at 1:23 am
eg.
CASE Type
WHEN 1 THEN Select * from table1
WHEN 2 THEN Select * from Table 2
ELSE Select * from Table 3
END
Am finding difficulty to write the Select statements.Please help me !
January 29, 2014 at 1:51 am
Can you show the context in which this would be used?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 29, 2014 at 3:38 am
Based on the Type I need to query different tables to get the data.
I hope this helps!
January 29, 2014 at 3:48 am
Not really. CASE is used within a query. Can you post the whole query within which you want to use the CASE construct?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 29, 2014 at 4:20 am
So as per your comments, I need to use multiple If's.... But if there are more than 100 types , then having 100 if's would not be good practice ?
January 29, 2014 at 4:24 am
sabeer.mvit (1/29/2014)
So as per your comments, I need to use multiple If's.... But if there are more than 100 types , then having 100 if's would not be good practice ?Regards,
Sabeer
No, I've said nothing about IF. Post the whole query in which you want to use your CASE.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 29, 2014 at 4:43 am
The sample query that I have mentioned in my post is the similar to what I need to write.
January 29, 2014 at 5:01 am
Where does the column [Type] come from?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 29, 2014 at 6:10 am
Surely the only way you'd achieve this is with dynamic sql, which would be an absolute pig to maintain. Could you combine the various table you want to query into a single view, exposing the type too, then join on to the view?
January 29, 2014 at 7:39 am
Farlzy (1/29/2014)
Surely the only way you'd achieve this is with dynamic sql, which would be an absolute pig to maintain.
That is a pretty bold statement to make when we don't really know what the OP is trying to do.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply