SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Varchar(max)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Clages1
Yak Posting Veteran

67 Posts

Posted - 04/27/2013 :  18:25:54  Show Profile  Reply with Quote
Hi

declare @x varchar(max)

select @ax = REPLICATE('a',2000)
select @bx = REPLICATE('b',2000)
select @cx = REPLICATE('c',2000)
select @dx = REPLICATE('d',2000)
select @ex = REPLICATE('e',2000)

select @x = @ax + @bx + @cx + @dx + @ex

why this select SUBSTRING(@x,9000,150) dont bring to me 'eeeeeee'?
where is my mistake?
tks
Clages



Clages1
Yak Posting Veteran

67 Posts

Posted - 04/27/2013 :  18:44:11  Show Profile  Reply with Quote
Hi its me again
I found this solution.

set @x = Cast(@ax as Varchar(max)) +
Cast(@bx as Varchar(max)) +
Cast(@cx as Varchar(max)) +
Cast(@dx as Varchar(max)) +
Cast(@ex as Varchar(max))
select SUBSTRING(@x,9000,150)

now works fine,
is there another solution?
tks again

CLages
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17681 Posts

Posted - 04/27/2013 :  22:58:43  Show Profile  Reply with Quote
is @ax to @ex also varchar(max) ?


KH
Time is always against us

Go to Top of Page

Clages1
Yak Posting Veteran

67 Posts

Posted - 04/29/2013 :  12:02:30  Show Profile  Reply with Quote
No, they are @Ax to @ex varchar(8000)
tks
Clages
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3741 Posts

Posted - 04/29/2013 :  12:14:00  Show Profile  Reply with Quote
Think of it as computing the right hand side (using the data types it is given) and then assigning the result to the left hand side variable. Since all the variables on the right hand side are varchar(8000), the intermediate result it calculates is also varchar(8000).

You can get around this by doing what you did, or even simply this, which forces the intermediate result to varchar(max)

SELECT @x = CAST(@ax AS VARCHAR(MAX)) + @bx + @cx + @dx + @ex
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000