且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

写下面的查询输出请回复我

更新时间:2023-01-23 19:30:40

这有点复杂,但也不算太糟糕。



但是......这有一种强烈的家庭作业气味,如果只是因为没有人想要真正做到这一点,因为月份名称将是在SQL Server PC的文化中,而不是显示PC。结果,我不会给你代码!



但这里有一些提示:

1)你可以声明变量在SQL Server中:

  DECLARE   @ M   int  

例如,声明一个名为@M的整数

2)您可以使用类似的语法声明一个临时表来保存您的数据:

  DECLARE   @TAB  ([月份号]  INT ,[月份名称]  VARCHAR  20 ))



3)你可以运行带有WHILE的SQL循环:

  WHILE  @ M < = 12)
BEGIN
...
END 水疗n>



4)有一个DATENAME函数可以返回一个月的名字

 DATENAME(月份) ,CAST('  2013-04-01'  AS   DATE ))

将返回April

5)您可以直接从临时表返回数据:

  SELECT  *  FROM   @ TAB  





那么,你准备好了吗?


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]

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:
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:

DECLARE @TAB TABLE ([Month No] INT, [Month Name] VARCHAR(20))


3) You can run a loop in SQL with WHILE:

WHILE (@M <=12)
BEGIN
...
END


4) There is a DATENAME function which returns the name of a month

DATENAME(Month, CAST('2013-04-01' AS DATE))

Will return April
5) You can return data directly from a temporary table:

SELECT * FROM @TAB



So, you up for it?