September 5, 2017 at 12:12 am
Comments posted to this topic are about the item Temporary tables SCOPE
September 5, 2017 at 1:01 am
Nice question, thanks Carlo.
enjoyed the red herrings in the options...
the "DROP TABLE IF EXISTS #Table" is very handy, too
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
September 5, 2017 at 1:26 am
Drat! Read it totally wrong and wanted to select 3 answers, then picked the wrong 2.
September 5, 2017 at 4:27 am
Good question, thanks. Made me really think hard! Good stuff!
September 5, 2017 at 6:36 am
Heh, I was so confident of my answer being "obviously" correct that I expected to find out that I was wrong about how EXECUTE() functions.
September 5, 2017 at 2:54 pm
BillLudlow - Tuesday, September 5, 2017 1:26 AMDrat! Read it totally wrong and wanted to select 3 answers, then picked the wrong 2.
The same. Thanks, Carlo!
September 5, 2017 at 4:02 pm
Why do I feel that this was a very easy question?
September 5, 2017 at 4:07 pm
Lynn Pettis - Tuesday, September 5, 2017 4:02 PMWhy do I feel that this was a very easy question?
Because you are who you are, my friend.
September 5, 2017 at 6:29 pm
Lynn Pettis - Tuesday, September 5, 2017 4:02 PMWhy do I feel that this was a very easy question?
Agreed. I was looking for the trick, but it was just the very important point about scope. It may sound scary, but I use the approach covered in the second batch frequently. It's very handy when I can't know the return column names when they're built dynamically.
Nice question, Carlo. Thanks.
September 7, 2017 at 4:35 pm
I must be missing something because I tried to execute this SQL and all I received was error 156 incorrect syntax near the keyword 'if'
_____________________________
Past performance != future results.
All opinions and suggestions are my own, unless they're really good. Then I most likely read them here...
September 7, 2017 at 4:39 pm
ChrisCarsonSQL - Thursday, September 7, 2017 4:35 PMI must be missing something because I tried to execute this SQL and all I received was error 156 incorrect syntax near the keyword 'if'
What version of SQL Server are using? IIRC, the syntax used in this question is for SQL Server 2016 and newer.
September 8, 2017 at 12:48 am
ChrisCarsonSQL - Thursday, September 7, 2017 4:35 PMI must be missing something because I tried to execute this SQL and all I received was error 156 incorrect syntax near the keyword 'if'
What sql server version are you using?
(try with sql server 2016)
September 8, 2017 at 8:55 am
ChrisCarsonSQL - Thursday, September 7, 2017 4:35 PMI must be missing something because I tried to execute this SQL and all I received was error 156 incorrect syntax near the keyword 'if'
Only first line will not work in the prior versions, it will work only from 2016 version. But main code to related to temp table will work, you can drop the temp table the way you drop normal tables, or just close the window in SSMS
September 8, 2017 at 12:15 pm
Lynn Pettis - Thursday, September 7, 2017 4:39 PMChrisCarsonSQL - Thursday, September 7, 2017 4:35 PMI must be missing something because I tried to execute this SQL and all I received was error 156 incorrect syntax near the keyword 'if'What version of SQL Server are using? IIRC, the syntax used in this question is for SQL Server 2016 and newer.
That was the issue. Thank you!
_____________________________
Past performance != future results.
All opinions and suggestions are my own, unless they're really good. Then I most likely read them here...
September 26, 2017 at 7:54 am
Just to add:
There is different behavior on SQL-Server 2012. I have to change the statement to (there is no 'if exists')
if object_id ('tempdb..#t') is not null drop table #t
execute ('create table #t (i int, z int)')
select * from #t
GO
-- second Batch
if object_id ('tempdb..#t') is not null drop table #t
create table #t (i int)
execute ('alter table #t add z int')
select * from #t
There is an error on SQL-Server 2012:
Msg 208, Level 16, State 0, Line 3
Invalid object name '#t'.
The resut will be i,z.
Learning buy doing.
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply