Click here to Skip to main content
15,898,950 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, can anyone teach me how to convert from bigint to nvarchar in stored procedure.

Here are some field related in my db:

Table A
CmpntID bigint

Table B
ComplaintID nvarchar50

I wanna insert the data of CmpntID in Table A to ComplaintID field in Table B

the query goes like this : (Already declare @ CmpntID)


SELECT @CmpntID = CmpntID <--here i should convert it right, but i don't know how
FROM TABLE A WHERE CmpntID = @CmpntID
Posted
Updated 18-Jul-13 21:47pm
v2

declare @CmpntID BigINT
SELECT CAST(@CmpntID AS VARCHAR) = CmpntID from TableA
 
Share this answer
 
Comments
Mare7 19-Jul-13 3:45am    
I write ur solution in my stored procedure. however the line turns to error which said "A select statement that assigns a value to a variable must not be combined with data retrieval operations. and when i execute it, its throwing an error such as Incorrect syntax near '='.
Mare7 19-Jul-13 5:18am    
Owh..juz need to change the position only. Tq for responding to my question..i appreciate it a lot. thx again
jaideepsinh 19-Jul-13 5:25am    
Can you please accept as answer and vote.
SQL
SELECT @CmpntID = CAST(ComplaintID AS BIGINT)
 
Share this answer
 
v2
Comments
Mare7 19-Jul-13 5:01am    
Hi,thx chicam. i change it a little and it works great. thx a lot.
here is what i do --> SELECT @CmpntID = CAST(CmpntID AS VARCHAR)
berrymaria 19-Jul-13 5:12am    
Oh! I just thought you need to assign and cast ComplaintID to bigInt, but then it was the CompntID to be Varchar. Can you accept my answer? :)
Mare7 19-Jul-13 5:16am    
Of Course. Thx again..
berrymaria 19-Jul-13 5:28am    
You're welcome :) and Thank you too! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900