October 8, 2014 at 9:32 am
Hi,
Have the following in my SELECT statement, which I'm having issues with when I modify it to include a CAST or a CONVERT.
CONCAT(PER.[PERSON-REF],ROW_NUMBER() OVER (PARTITION BY PER.[PERSON-REF] ORDER BY TEN.[tenancy-ref])) AS 'ID'
How do I convert or cast it to a varchar (20)?
Thanks
October 8, 2014 at 9:42 am
Where do you want to include CAST or CONVERT?
October 8, 2014 at 9:44 am
nto very clear what exactly you want to CAST or CONVERT, but lets assume it;'s a ROW_NUMBER...
CONCAT(PER.[PERSON-REF]
,CAST(ROW_NUMBER() OVER (PARTITION BY PER.[PERSON-REF]
ORDER BY TEN.[tenancy-ref]) AS VARCHAR(20)) AS 'ID'
October 8, 2014 at 9:47 am
I'm trying to cast/Convert the whole of the concatenation result. I take it you cant' do that?
October 8, 2014 at 9:50 am
TSQL Tryer (10/8/2014)
I'm trying to cast/Convert the whole of the concatenation result. I take it you cant' do that?
You can, but in your case it will fail before getting there anyway, as ROW_NUMBER needs to be converted to varchar first...
October 8, 2014 at 9:51 am
Thanks Eugene Elutin, what you've suggested has worked for me.
October 8, 2014 at 9:52 am
You would need to convert the numeric to a string type in order to concatenate it. The concat accepts strings rather than numerics.
From BOL
CONCAT takes a variable number of string arguments
http://msdn.microsoft.com/en-us/library/hh231515.aspx
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
October 8, 2014 at 10:00 am
That's weird, I'm sure that integers would be implicitly converted into strings as shown on the examples from BOL.
October 8, 2014 at 10:17 am
Luis Cazares (10/8/2014)
That's weird, I'm sure that integers would be implicitly converted into strings as shown on the examples from BOL.
You are absolutely right, CONCAT works without any conversion. So, my comment about error should be withdrawn.
Have not used CONCAT much myself...
So, have no idea what actually didn't work for OP.
May be it's due to some SET options?
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply