Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 convert

Author  Topic 

oracle_corrgi
Yak Posting Veteran

98 Posts

Posted - 2007-01-31 : 02:28:05
hi
how can i convert smallint to varchar
declare @over smallint
[rollover_txn] = CASE WHEN hh.[deint] & ' + CAST(varchar(5),@over)+ ' = ' + CAST(varchar(5),@over) + ' THEN 1 ELSE 0 END,



krmm

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-31 : 02:30:09
[code]select convert(varchar(10), @over)[/code]


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-31 : 02:34:01
& is a BITWISE operator for AND, not concatenating. For this you use + sign.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

oracle_corrgi
Yak Posting Veteran

98 Posts

Posted - 2007-01-31 : 03:15:36
Syntax error converting the varchar value ' + convert(varchar(10), @OVER)+ ' to a column of data type smallint.

krmm
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-31 : 03:16:38
See this topic http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=78351


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-31 : 03:20:38
The string above is evaluated as "+4544+". The last plus sign is invalid.
If you have no clue of dynamic sql, stay away from it!

Read more here http://www.sommarskog.se/dynamic_sql.html about dynamic sql.
Please do so!


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

oracle_corrgi
Yak Posting Veteran

98 Posts

Posted - 2007-01-31 : 03:31:53
can any one convert smallint to varchar for the above query

krmm
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-31 : 03:37:05
is that the complete query ?


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-31 : 03:43:15
Oracle_Corrgi, you are SO overcomplicating things.
Learn to think T-SQL way, not C/C++ nor VB/VB.Net way!!!!


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

oracle_corrgi
Yak Posting Veteran

98 Posts

Posted - 2007-01-31 : 03:45:29
there r but i have one column to convert from smallint to varchar

krmm
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-31 : 03:48:12
"is that the complete query ?"
And also you have irritating tendancy of not paying attention to what we are suggesting/asking here!

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-31 : 03:48:37
khtan told you how to do it! That is the proper way!
The error occurs later because YOU DO NOT KNOW HOW TO PROPER USE DYNAMIC SQL!


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-31 : 04:10:27
Without the complete query, the best that i can help is

use
convert(varchar(10), <your smallint value>)



KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-31 : 04:12:18
is this thread related to http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=78351 ?


KH

Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-01-31 : 05:10:25
uuu a circular reference khtan!!
that's confusing



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-31 : 07:30:02
Very Sorry. I was confused by the OP on both threads


KH

Go to Top of Page
   

- Advertisement -