Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
Set command to concatteneate strings
Set command to concatteneate strings
Rate Topic
Display Mode
Topic Options
Author
Message
gerard-593414
gerard-593414
Posted Sunday, August 05, 2012 3:03 AM
Grasshopper
Group: General Forum Members
Last Login: Tuesday, January 29, 2013 5:15 AM
Points: 22,
Visits: 34
I am trying to use a variabe to camcattenate a string
I use following:
DECLARE @MYVAR Char(1000) = 'INITIAL'
if Conditon 1
SET @MYVAR = @MYVAR + ' ABC'
If Condition 2
SET @MYVAR = @MYVAR + 'DEF'
But Myvar nver changes from the Initial value
Post #1340254
SomewhereSomehow
SomewhereSomehow
Posted Sunday, August 05, 2012 6:57 AM
SSC Journeyman
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 10:52 PM
Points: 75,
Visits: 410
gerard-593414 (8/5/2012)
I am trying to use a variabe to camcattenate a string
I use following:
DECLARE @MYVAR Char(1000) = 'INITIAL'
if Conditon 1
SET @MYVAR = @MYVAR + ' ABC'
If Condition 2
SET @MYVAR = @MYVAR + 'DEF'
But Myvar nver changes from the Initial value
Nice trick!=)))
try
DECLARE @MYVAR
var
Char(1000) = 'INITIAL'
When you declare variable like char(n) and set it, the first M symbols will be set ('INITIAL'-7 chars in your case), other 1000-7=993 symbols will be ' '.
After that when you selecting variable in SSMS - it won't show you all the 1000 symbols, instead it will show you the several first one, and it will seem like 'INITIAL '.
I am really sorry for my poor gramma. And I hope that value of my answers will outweigh the harm for your eyes.
Blog: http://somewheresomehow.ru
Twitter: @SomewereSomehow
Post #1340262
gerard-593414
gerard-593414
Posted Sunday, August 05, 2012 7:59 AM
Grasshopper
Group: General Forum Members
Last Login: Tuesday, January 29, 2013 5:15 AM
Points: 22,
Visits: 34
Ok thanks for that.
So each time I Rtrim the variable and it seems to work
Post #1340272
SomewhereSomehow
SomewhereSomehow
Posted Sunday, August 05, 2012 8:16 AM
SSC Journeyman
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 10:52 PM
Points: 75,
Visits: 410
Yes, because it trims all the right spaces. So maybe you should consider to change data type to varchar.
Good luck!
I am really sorry for my poor gramma. And I hope that value of my answers will outweigh the harm for your eyes.
Blog: http://somewheresomehow.ru
Twitter: @SomewereSomehow
Post #1340275
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.