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
 General SQL Server Forums
 New to SQL Server Programming
 convert to nvarchar
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vack
Constraint Violating Yak Guru

USA
497 Posts

Posted - 12/21/2012 :  08:58:38  Show Profile  Reply with Quote

@Startvalue is int

How do I convert the following to nvarchar?

@StartValue + Row_number() over (order by (select 1))

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 12/21/2012 :  09:00:51  Show Profile  Reply with Quote
CAST ( yourPart AS NVARCHAR)

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/21/2012 :  09:01:05  Show Profile  Reply with Quote
if you want values to be appended

CAST(@StartValue AS nvarchar(10)) + CAST(ROW_NUMBER() over (order by (select 1)) AS varchar(5))

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/21/2012 :  09:07:24  Show Profile  Reply with Quote
If your @startvalue is for example 10, and you want to get 11,12,13 etc. do this:

CAST(@StartValue + Row_number() over (order by (select 1)) AS NVARCHAR(5));


If your @startvalue is for example 10, and you want to get 101,102,...109,1010,1011 etc., do this:

CAST(@StartValue AS NVARCHAR(5)) + CAST(Row_number() over (order by (select 1)) AS NVARCHAR(5));
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 12/24/2012 :  03:00:29  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by Vack


@Startvalue is int

How do I convert the following to nvarchar?

@StartValue + Row_number() over (order by (select 1))


Because they sound like numbers, you don't need to convert them to nvarchar

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/24/2012 :  15:18:28  Show Profile  Reply with Quote
quote:
Originally posted by madhivanan

quote:
Originally posted by Vack


@Startvalue is int

How do I convert the following to nvarchar?

@StartValue + Row_number() over (order by (select 1))


Because they sound like numbers, you don't need to convert them to nvarchar

Madhivanan

Failing to plan is Planning to fail


What if requirement was appending rather than integer addition?


Unless OP posts sample data and expected output we cant determine what exactly the intended result is..

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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