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.
Author |
Topic |
madlo
Starting Member
41 Posts |
Posted - 2015-05-04 : 05:46:05
|
I need a query to always give output irrespective if the table exists or not. If it doesn't exists it just returns no rows but does return the columns.The query will be used in SQL Server Analysis Services as a fact tableI have the following query simplifiedIF object_id('MyTable', 'U') is not NULLBEGIN Select ColA,ColB,ColC from MyTableELSEBEGIN CREATE TABLE #MyTempTable]( [ColA] [int] , [ColB] [nvarchar](30), [ColC] [nvarchar](30) ,)Select * from MyTempTableENDThis query runs perfect outside analysis services.However when I put it in analysis services fact table is equivalent to making the above query a nested select ofSelect * from (//If select )MyTableI then get an error Msg 156, Level 15, State 1, Line 5Incorrect syntax near the keyword 'IF'.because it doesn't like the if statement in the nested select.Any possible way to put a nested if statement inside a subquery? |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-05-04 : 12:41:50
|
within a query, CASE is used instead of IFGerald Britton, MCSAToronto PASS Chapter |
|
|
|
|
|