Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


how to cut blank space from var

Posted on 2011-10-29
Medium Priority
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

Accepted Solution

DerSpinner earned 2000 total points
ID: 37049828
how about CAST(count as char(1))?
LVL 143

Expert Comment

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

571 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