Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

T-SQL Expand / Collapse
Author
Message
Posted Thursday, November 13, 2008 11:09 PM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Yesterday @ 11:43 AM
Points: 1,477, Visits: 2,100
Comments posted to this topic are about the item T-SQL

Jason Shadonix
MCTS, SQL 2005
Post #602522
Posted Thursday, November 13, 2008 11:27 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 5:31 PM
Points: 2,953, Visits: 435
Nice! I almost got tricked. If you had put
1 Test Policy 150000.00
2 Policy1 250000.00
3 0.00
in the answer, I would have chosen it, but because this answer doesn't exist, it makes me re-read the query again carefully and noticed that the INSERT is actually part of the stored procedure.



Urbis, an urban transformation company
Post #602527
Posted Friday, November 14, 2008 12:30 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, September 18, 2013 2:20 AM
Points: 216, Visits: 169
As i read through the code, i didn't even realize that the second insert could possibly have been intented to be outside the sp, so in my mind the table had to contain 4 records as the sp was executed 2 times, taking into account that the sp can be executed without any values passed into it due to the default values on the parameters.
I was actually looking for other kinds of traps ;)
Post #602554
Posted Friday, November 14, 2008 5:33 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Friday, April 12, 2013 12:23 PM
Points: 606, Visits: 587
Nice Very tricky. I ran each statement separately. I answer it as TABLEA. I read comments posted and tried again, then only I got TABLEC.
Post #602644
Posted Friday, November 14, 2008 6:22 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:57 AM
Points: 6,544, Visits: 8,759
Iggy (11/13/2008)
Nice! I almost got tricked. If you had put
1 Test Policy 150000.00
2 Policy1 250000.00
3 0.00
in the answer, I would have chosen it, but because this answer doesn't exist, it makes me re-read the query again carefully and noticed that the INSERT is actually part of the stored procedure.


I would have fallen into the same boat you would have.


Wayne
Microsoft Certified Master: SQL Server 2008
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #602672
Posted Friday, November 14, 2008 7:23 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:24 PM
Points: 11,990, Visits: 11,007
I fell victim to a similair script at one point. As a result I now make it my standard habit that after the declaration of the sp i wrap the entire body in a begin end.

declare myProc() as
begin

end

Once you stub in the solid open and closing it is very easy to fill in the body and even more difficult to accidentally leave something inside the proc.


_______________________________________________________________

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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #602735
Posted Friday, November 14, 2008 7:31 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 2:48 AM
Points: 3,089, Visits: 7,745
I don't agree with calling this tricky. It's only tricky if you start making assumption about what might have been intended as opposed to what is actually there.





Alvin Ramard
Memphis PASS Chapter

All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.
Post #602743
Posted Friday, November 14, 2008 7:36 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, September 18, 2013 2:20 AM
Points: 216, Visits: 169
As a result I now make it my standard habit that after the declaration of the sp i wrap the entire body in a begin end.


that is maybe not a bad habit to develop...
it's getting it to become a habit that's the problem:D
Post #602747
Posted Friday, November 14, 2008 7:36 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, August 17, 2011 7:09 AM
Points: 869, Visits: 963
Nothing like a good trick question on a Friday morning to keep you on your toes!
Post #602749
Posted Friday, November 14, 2008 8:27 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 12:10 PM
Points: 3,766, Visits: 3,584
slange (11/14/2008)

I now make it my standard habit that after the declaration of the sp i wrap the entire body in a begin end.

declare myProc() as
begin

end

Once you stub in the solid open and closing it is very easy to fill in the body and even more difficult to accidentally leave something inside the proc.


When you script out stored procedures in SQL 2005, it does not add the 'GO' to the bottom of the script as it did in SQL 2000. Consequently we have developers who script out their stored procedures for the install script and forget to add the 'GO' and end up with bonus commands in their stored procedure (if I don't catch it). So I also made it a best practice to use the begin and end to denote the stored procedure body. This question illustrates the problem.

Thanks for the question.
Post #602818
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse