Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
write the query below output please reply me currect answer

number  month
1       january
2       february
3       march
.        .
.        . 
.        .
.        .
.        .
12      december

write the in sql want above output

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 1-Apr-13 8:03am
v2
Comments
joshrduncan2012 1-Apr-13 13:59pm    
Not a question...and besides it doesn't work like that here.
Richard C Bishop 1-Apr-13 14:27pm    
How will you be paying for this service? I take cash or check.
BillW33 1-Apr-13 14:31pm    
Try writing the query yourself then folk will be glad to help you with any problems you have.

1 solution

It's a little complex, but not too bad.

But...this has a strong smell of homework about it, if only becuase no-one ould want to do that for real, as teh month name would be in the culture of the SQL Server PC, not the displaying PC. As a result, I won't give you the code!

But here are some hints:
1) You can declare variables in SQL Server:
SQL
DECLARE @M int
For example, declares an integer, called "@M"
2) You can use similar syntax to declare a temporary table to hold your data:
SQL
DECLARE @TAB TABLE ([Month No] INT, [Month Name] VARCHAR(20))

3) You can run a loop in SQL with WHILE:
SQL
WHILE (@M <=12)
BEGIN
...
END

4) There is a DATENAME function which returns the name of a month
SQL
DATENAME(Month, CAST('2013-04-01' AS DATE))
Will return April
5) You can return data directly from a temporary table:
SQL
SELECT * FROM @TAB


So, you up for it?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900