代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
MSSQL
】
求某段时间内星期几的天数
作者:
Dezai.CN
/ 发布于
2012/2/8
/
706
<div> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">原帖地址:</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><a href="http://blog.csdn.net/DengXingJie/archive/2011/02/25/6208762.aspx">http://blog.csdn.net/DengXingJie/archive/2011/02/25/6208762.aspx</a></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">/*</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">**********************************************</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">Program ID: FUN_GetDaysOfWeek</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">Purpose<span style="mso-spacerun: yes;"> </span>: </span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">求某段时间内某一星期日期的天数</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">Author<span style="mso-spacerun: yes;"> </span>: Jesse</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">Date<span style="mso-spacerun: yes;"> </span>: 2011.02.19</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">**********************************************</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">*/</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">go</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">Create</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">Function</span> dbo<span style="color: gray;">.</span>FUN_GetDaysOfWeek<span style="color: gray;">(</span><span style="mso-spacerun: yes;"> </span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@DateS <span style="color: blue;">smalldatetime</span><span style="color: gray;">,</span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">开始时间</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@DateE <span style="color: blue;">smalldatetime</span><span style="color: gray;">,</span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">结束</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@WeekValue <span style="color: blue;">int</span><span style="color: gray;">)</span><span style="mso-spacerun: yes;"> </span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">星期的某一天:</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">-</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">周日、</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">-</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">周一</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">...7-</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">周六</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">Returns</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>100<span style="color: gray;">)</span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">As</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">Begin</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">declare</span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>@sResult <span style="color: blue;">nvarchar</span><span style="color: gray;">(</span>100<span style="color: gray;">),</span><span style="mso-spacerun: yes;"> </span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">结果描述</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>@nResult <span style="color: blue;">int</span><span style="color: gray;">,</span><span style="mso-spacerun: yes;"> </span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">结果天数</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>@nWeekValue <span style="color: blue;">int</span><span style="color: gray;">,</span><span style="mso-spacerun: yes;"> </span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">起始日期是星期几</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(1-</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">周日、</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">-</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">周一</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">...7-</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">周六</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">)</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>@nDays <span style="color: blue;">int</span><span style="color: gray;">,</span><span style="mso-spacerun: yes;"> </span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">时间段内的天数</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>@nBeforeDays <span style="color: blue;">int</span><span style="color: gray;">,</span><span style="mso-spacerun: yes;"> </span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">起始日期到第一次相符日期的天数</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>@sWeekName <span style="color: blue;">varchar</span><span style="color: gray;">(</span>20<span style="color: gray;">),</span><span style="mso-spacerun: yes;"> </span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">所求日期的星期名称</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>@tmpDate <span style="color: blue;">smalldatetime</span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">set</span> @WeekValue<span style="color: gray;">=</span>@WeekValue <span style="color: gray;">%</span> 7</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">if</span> @WeekValue<span style="color: gray;">=</span>0 </span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">set</span> @WeekValue<span style="color: gray;">=</span>7</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> </span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">如果起始日期大于终止日期,则对换</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">if</span> @DateS<span style="color: gray;">></span>@DateE</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">select</span> @tmpDate<span style="color: gray;">=</span>@DateE<span style="color: gray;">,</span>@DateE<span style="color: gray;">=</span>@DateS<span style="color: gray;">,</span>@DateS<span style="color: gray;">=</span>@tmpDate</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> </span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">取得起始日期的星期数,与设置无关</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(1-</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">周日、</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">-</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">周一</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">...7-</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">周六</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">)</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">select</span> @nWeekValue<span style="color: gray;">=(</span><span style="color: fuchsia;">Datepart</span><span style="color: gray;">(</span>dw<span style="color: gray;">,</span>@DateS<span style="color: gray;">)+(</span><span style="color: fuchsia;">@@Datefirst</span> <span style="color: gray;">%</span>7<span style="color: gray;">))%</span>7</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">if</span> @nWeekValue<span style="color: gray;">=</span>0</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">set</span> @nWeekValue<span style="color: gray;">=</span>7</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">set</span> @sWeekName<span style="color: gray;">=</span><span style="color: fuchsia;">DateName</span><span style="color: gray;">(</span>dw<span style="color: gray;">,</span><span style="color: fuchsia;">DateAdd</span><span style="color: gray;">(</span>d<span style="color: gray;">,</span>@WeekValue<span style="color: gray;">-</span>@nWeekValue<span style="color: gray;">,</span>@DateS<span style="color: gray;">))</span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: gray; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> </span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">if</span> @WeekValue<span style="color: gray;">>=</span>@nWeekValue</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">set</span> @nBeforeDays<span style="color: gray;">=</span>@WeekValue<span style="color: gray;">-</span>@nWeekValue</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">else</span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">set</span> @nBeforeDays<span style="color: gray;">=</span>7<span style="color: gray;">-</span><span style="color: fuchsia;">abs</span><span style="color: gray;">(</span>@WeekValue<span style="color: gray;">-</span>@nWeekValue<span style="color: gray;">)</span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: gray; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> </span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">--</span></span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">取得时间段内的天数</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">select</span> @nDays<span style="color: gray;">=</span><span style="color: fuchsia;">Datediff</span><span style="color: gray;">(</span>d<span style="color: gray;">,</span>@DateS<span style="color: gray;">,</span>@DateE<span style="color: gray;">)+</span>1</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">if</span> @nDays<span style="color: gray;"><</span>@nBeforeDays</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">select</span> @nResult<span style="color: gray;">=</span>0</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">else</span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">select</span> @nResult<span style="color: gray;">=</span><span style="color: fuchsia;">ceiling</span><span style="color: gray;">((</span>@nDays<span style="color: gray;">-</span>@nBeforeDays<span style="color: gray;">)/</span>7.0<span style="color: gray;">)</span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">set</span> @sResult<span style="color: gray;">=</span>N<span style="color: red;">'</span></span><span style="color: red; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">日期区间:</span><span lang="EN-US" style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">'</span><span lang="EN-US" style="color: gray; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">+</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>10<span style="color: gray;">),</span>@DateS<span style="color: gray;">,</span>120<span style="color: gray;">)+</span> N<span style="color: red;">' </span></span><span style="color: red; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">到</span><span lang="EN-US" style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">'</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: gray;">+</span><span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>10<span style="color: gray;">),</span>@DateE<span style="color: gray;">,</span>120<span style="color: gray;">)</span> <span style="color: gray;">+</span><span style="color: red;">' </span></span><span style="color: red; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">之间</span><span lang="EN-US" style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">'</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: gray;">+</span>@sWeekName <span style="color: gray;">+</span>N<span style="color: red;">' </span></span><span style="color: red; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">共有</span><span lang="EN-US" style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">'</span><span lang="EN-US" style="color: gray; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">+</span><span lang="EN-US" style="color: fuchsia; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">cast</span><span lang="EN-US" style="color: gray; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@nResult <span style="color: blue;">as</span> <span style="color: blue;">varchar</span><span style="color: gray;">(</span>100<span style="color: gray;">))+</span>N<span style="color: red;">' </span></span><span style="color: red; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">天</span><span lang="EN-US" style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">'</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">Return</span> @sResult</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">end</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> </span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">go</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">测试示例</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">select</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> dbo<span style="color: gray;">.</span>FUN_GetDaysOfWeek<span style="color: gray;">(</span><span style="color: red;">'2011-03-01'</span><span style="color: gray;">,</span><span style="color: red;">'2011-05-31'</span><span style="color: gray;">,</span>1<span style="color: gray;">)</span></span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: gray; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> </span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--</span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">运行结果</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">/*</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">日期区间:<span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">2011</span></span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">-03-01 </span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">到</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">2011-05-31</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> </span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">之间</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">Sunday </span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">共有</span><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">13 </span><span style="color: green; font-family: 宋体; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-ascii-font-family: "Courier New"; mso-hansi-font-family: "Courier New"; mso-bidi-font-family: "Courier New";">天</span> <p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left; mso-layout-grid-align: none;"><span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">*/</span> </div>
试试其它关键字
某段时间
同语言下
.
SQL查询 多列合并成一行用逗号隔开
.
查看存储过程修改时间,最近执行时间
.
设置手动批量删除数据库相关进程
.
获取某个表中特定字段的所有字符串形式
.
SQL 如何去除重复的字符串
.
怎么去掉一个字段中的重复数据
.
String 去除空格 回车 换行 水平制表符
.
SQL查询和替换含有回车,空格,TAB
.
SQL SERVER 查询每日新增用户数量、次留数量
.
判断两个字符串是否存在相同的内容
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3