Sunday, February 26, 2012

Format number in stored procedure

I have one question about stored procedure. I will write expression
which I used and result what I want:
Cast(InvNumber as varchar)+'/'+cast(year(InvDate) as varchar) results
as 75/2006. I want it to result as 00075/2006. How can I do it?Here is an example, but this should be done at the front-end
declare @.InvNumber int
select @.InvNumber = 75
SELECT @.InvNumber, RIGHT('0000000000' + Cast(@.InvNumber as
varchar)+'/'+cast(year(getdate()) as varchar),10)
Denis the SQL Menace
http://sqlservercode.blogspot.com/|||Thanks for your response,
I can not use code which you propose because I have many InvNumber not
only one. This number 75 was only sample number.
Regards,|||Sure you can, that was just an example
SELECT RIGHT('0000000000' + Cast(InvNumber as
varchar)+'/'+cast(year(InvDate) as varchar),10)
FROM ...
Denis the SQL Menace
http://sqlservercode.blogspot.com/|||I got the error message: Subquery returned more than 1 value. It is not
allowed etc.|||Can you show use the query you executed?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
<lemes_m@.yahoo.com> wrote in message news:1147965460.658957.270150@.y43g2000cwc.googlegroups.
com...
>I got the error message: Subquery returned more than 1 value. It is not
> allowed etc.
>

No comments:

Post a Comment