Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Parameter concatenation with integer


Message #1 by "Bill Robinson" <Bill.Robinson@S...> on Wed, 24 Jan 2001 19:11:47 -0000
--0-236931896-980505951=:32432
Content-Type: text/plain; charset=us-ascii


Bill

I have been loking at this one with interest

My code works

Create Procedure rts_ReadText_select
@tablename nvarchar(25),
@id nvarchar(5)
as
execute ('SELECT * FROM ' + @tablename + ' WHERE Resid = ' + @id + ' ORDER BY BulletinId DESC ' )
go


Notice I am using a char for the @id

and Executing the query

Which you need to do

Also watch out for the spaces befor and after the variables i.e. 

after FROM and before WHERE

 Roland 

  Duncan Faulkner <DuncanF@R...> wrote: 
Bill 

try this, replace with actual table name I dont think SQL likes
a variable where a table should be....

Also remove single quotes and plus signs...


SELECT * FROM WHERE RefNo = @refno 
ORDER BY Stamp DESC, Counter ASC

Duncan



-----Original Message-----
From: Bill Robinson [mailto:Bill.Robinson@S...]
Sent: 24 January 2001 19:12
To: sql language
Subject: [sql_language] Parameter concatenation with integer


I am attempting to create a stored procedure that requires two parameters.
The first is Table Name which is defined as a 25 byte nvarchar. The second
is ReferralNumber which is defined as int. When I try to execute the 
following using rts_ReadText_select 'Txt_Comment, 132780...

Create Procedure rts_ReadText_select(@tablename nvarchar(25), @refno int)
AS

SELECT '* FROM ' + @tablename + 'WHERE RefNo = ' + @refno +
'ORDER BY Stamp DESC, Counter ASC'

I get the following error message:

Syntax error converting the varchar value '*FROM Txt_Comment WHERE RefNo 
' to a column of data type int.

If anyone can help me out with the correct syntax to make this query work
I would be eternally grateful.

Thanks,

Bill Robinson





---------------------------------
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.

  Return to Index