Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERTING INTEGERS INTO SQL-STRING

Status
Not open for further replies.

kissarmi

Programmer
Feb 14, 2002
72
US
Hi,

I am building SQL Strings in my stored procedure in order to execute with dynamic information. After much agony dealing with the single-quotes, double-quotes, when and when not to use quotes, etc..., I have them working. The problem is when I need to insert an integer variable into the string. I declare and set the int variable at the beginning of the SP. I can't get the variable inserted into the string as the integer value.

Thanks for any help.
 
Code:
declare @q varchar(8000)
declare @c int
set @q = 'insert into t(c) values(' + @c + ')'
exec(@q)

Could you be a bit more specific as to what is the problem? Myabe by showing some code and any errors you encounter.
 
Can you give an example of what you are trying to do?

First off, I would have to say that an INTEGER can't be included in a string. A string is a CHAR/VARCHAR/NCHAR/NVARCHAR data type and INTEGER isn't. You would have to do a CAST or CONVERT.

But I might be going the wrong way with this, depending on what you are really trying to do.

-SQLBill
 
SELECT &quot;<tr><td>&quot; + cast(intField as varchar(10)) + &quot;</td></tr>&quot; FROM myTable

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top