Link to home
Start Free TrialLog in
Avatar of bender007
bender007

asked on

Convert from Int to String

How do i convert a Int to a string.

I am trying to append a Integer value in a query.

SET @SQL = 'UPDATE status_table SET status' + CONVERT(varchar(10),@statusCount) + ' = ''' + @Old_status + ''''
ASKER CERTIFIED SOLUTION
Avatar of rmacfadyen
rmacfadyen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trainsdse
trainsdse

I agree with rmacfadyen, you might try casting instead though.  And here's how to fix @Old_Status too.

SET @SQL = 'UPDATE status_table SET status' + cast(@statusCount as varchar(10)) + ' = ''' + Replace(@Old_status,'''','''''') + ''''

what is the datatype of @Old_status ? if it is int try something like this

SET @SQL = 'UPDATE status_table SET status' + CONVERT(varchar(10),@statusCount) + ' = ''' + convert(varchar,@Old_status) + ''''
@old_status is varchar and StatusCount is int
then your sql should be ok, are you getting any error?
post the error message here
If @Old_status is char or varchar

SET @SQL = 'UPDATE status_table SET status' + CONVERT(varchar(10),@statusCount) + ' = ''' + ltrim(rtrim(@Old_status)) + ''''

if @Old_status is integer

SET @SQL = 'UPDATE status_table SET status' + CONVERT(varchar(10),@statusCount) + ' = ''' + CONVERT(varchar(10),@Old_status) + ''''
Avatar of Aneesh
bender007,
> I am trying to append a Integer value in a query.

You can use  CAST(urIntegerValue  as Varchar(10))
Error:


Msg 207, Level 16, State 1, Line 1
Invalid column name 'testuser'.
Avatar of bender007

ASKER

Error i get :
Msg 207, Level 16, State 1, Line 1
Invalid column name 'testuser'.
For petesakes... can you post the entire query? I bet if you search your query you will find the character sequence t, e, s, t, u, s, e, r... maybe not on line 1... but somewhere in there. From Query Analyzer's EDIT menu select FIND, type t, e, s, t, u, s, e, r and click the FIND NEXT button. This will bring you to the first occurrence... warning there may be more than one occurance. Be prepared to click the FIND NEXT button again!

Btw... if you meant to use a variable named @TestUser this error means you forgot the @ character somewhere.

but there is no 'testuser' column in your sql.
is the sql you are trying to execute is
SET @SQL = 'UPDATE status_table SET status' + CONVERT(varchar(10),@statusCount) + ' = ''' + @Old_status + ''''
or something different?

check the tables used in the error sql and make sure you have 'testuser' column in that table. or post your complete code(i think you are fixing some sp or batch sql)

are you using two ids bender007 and karthikram ?

DECLARE @statsCount int

SET @statsCount= (Select statusCount FROM status_table WHERE UserID = @user_id)

UPDATE status_table SET status' + CONVERT(varchar(10),@statusCount)  + '= @Old_status


This is what i was using initially.

testuser is a value in the table under UserID.


Yes I posted that message from a friends ID by mistake.

Thanks
What was the result of using the FIND function I suggested?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial