写下面的查询输出请回复我 [英] write the query below output please reply me

查看:51
本文介绍了写下面的查询输出请回复我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



<前lang =text>数字月
1月1日
2 2月
3月3日
。 。
。 。
。 。
。 。
。 。
12月12日



写入sql想要的上面输出



代码块添加 - OriginalGriff [/ edit]

解决方案

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



但是......这有一种强烈的家庭作业气味,如果只是因为没有人想要真正做到这一点,因为月份名称将是在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



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?


这篇关于写下面的查询输出请回复我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆