Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Request Help with stored procedure.
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00768818
Message ID:
00769724
Views:
21
>
>Opening Cursor
>tcQueryString=SELECT dbo.co_lu_Ident.recordid,dbo.co_lu_Ident.idtype,
>	 ISNULL(dbo.co_pat_ID.answerflag,0) as answerflag,
>	ISNULL(co_pat_id.pat_id_ID,0) as patidid
>FROM dbo.co_lu_Ident LEFT OUTER JOIN
>	dbo.co_Pat_ID ON dbo.co_lu_Ident.recordid = dbo.co_pat_ID.RecordID and co_Pat_ID.meetingnumber=@tiMeetID
>Server: Msg 137, Level 15, State 2, Line 5
>Must declare the variable '@tiMeetID'.
>
>
>
>Here is the code in the stored procedure:
>
>
>CREATE PROCEDURE ct_Get_Note_ListItems
>@tiNoteID int,
>@gnMeetID  int
>
>as
>declare @tiMeetID int
>set @tiMeetID=@gnMeetID
>
>declare c cursor local
>for select isnull(querystring,' ') as QueryString from NoteControlQueries where noteid=@tiNoteID
>
>print 'Opening Cursor'
>
>Open c
>
>
>declare @tcQueryString varchar(4000)
>
>fetch c into @tcQueryString
>
>close c
>print 'tcQueryString=' + @tcQueryString
>
>exec(@tcQueryString)
>
>
>


Is there any special reason why your using a cursor? If you just need to get the querystring out of the table you can use
select @tcQueryString = queryString from NoteControlQueries where noteid=@tiNoteID
Then I would just manually substitute the variable in.
select @tcQueryString = replace(@tcQueryString, '@tiMeetID', @tiMeetID)
Then just execute it
exec(@tcQueryString)
HTH
Eric Stephani
Previous
Reply
Map
View

Click here to load this message in the networking platform