how to cut blank space from var

Posted on 2011-10-29
Last Modified: 2012-06-27
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
Question by:rafaelrgl
    LVL 5

    Accepted Solution

    how about CAST(count as char(1))?
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    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.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Creating and Managing Databases with phpMyAdmin in cPanel.
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now