Register  Login  
  February 5, 2012  
Search_Blog Minimize
Print  

Blog_Archive Minimize
Print  

Blog    
View_Blog Minimize
Jan 9

Written by: host
Monday, January 09, 2006 7:13:00 PM 

Today I started to create a rather simple stored procedure that I thought would take a few minutes... Well it fell into the "20 minute" rule... if you estimate about "20 minutes" it won't be...

Anyway, this procedure needed to build SQL Select based on parameters passed in.  So, I needed to user SQL EXECUTE statement.  I create @SQL as the varchar that I contained the select statement and passed the command to the EXECUTE.. When procedure ran, I got the MSG 203  error message, but it was truncated due to the length of the SQL statement..  No problem, off to Books Online to determine what the MSG 203 message -- not there... Google?

OK .. 20 minutes later I finally discovered that any statement I passed into the EXECUTE statement did not work.  Hmmmm.  So back to the EXECUTE statement documentation.  Seems that I had missed a little detail.  If you are using a variable -- eg. @SQL in my case -- you must surround the EXECUTE parameter statement in brackets.  

So...(using the NorthWind database for example)

DECLARE @SQL AS VARCHAR(50)
SET @SQL = 'select * from orders'
EXEC @SQL

doesn't work, but

DECLARE @SQL AS VARCHAR(50)
SET @SQL = 'select * from orders'
EXEC (@SQL)   <-- notice the brackets

does...  lesson learned.   50 minutes later...  The "20 minute" rules lives!

Tags:

1 comment(s) so far...

Re: Chinese Footware - and the removal of...

GameCoach Factory Outlet Onlineare usuallyCoach Factoryin By Coach Outlet Online on   Thursday, February 02, 2012 1:27:13 AM


Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment   Cancel 

Blog_List Maximize
Print  

  Home | Blog | Forum | Subscriptions | Free Modules | Videos   Page generated in 0.156504 seconds.
  Copyright 2010 by TressleWorks   Terms Of Use | Privacy Statement