how to cut blank space from var

hi i have this code

declare @sql  varchar(4000)
declare @count int = 3
set @sql = 'select * from table1 where id =' + str(count)

ok, here we go, the result is this:

select * from table1 where id =      3

and i want this way withou this much space between the = and the number 3
with no space there, so i can use this number 3 in other part of my query. so i can combine with others fields as 1 field. anyways, how take of those extra spaces when converting from int to str?

select * from table1 where id =3
LVL 1
rafaelrglAsked:
Who is Participating?
 
DerSpinnerCommented:
how about CAST(count as char(1))?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I would not use CHAR(1), but VARCHAR(10), to avoid that if the value is 2 or more digits, that the value get's truncated.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.