首页 > 编程技术 > php

取得拼音字头的存储过程

发布时间:2016-11-25 16:44

-- =============================================
-- Create scalar function (NWGetPYFirst)
-- =============================================
IF EXISTS (SELECT *
FROM sysobjects
WHERE name = N'NWGetPYFirst')
DROP FUNCTION NWGetPYFirst
GO
CREATE FUNCTION NWGetPYFirst
(@str varchar(500) = '')
RETURNS varchar(500)
AS
BEGIN
Declare @strlen int,
@return varchar(500),
@ii int,
@c char(1),
@chn nchar(1)
--//初始化变量
Declare @pytable table(
chn char(2) COLLATE Chinese_PRC_CS_AS NOT NULL,
py char(1) COLLATE Chinese_PRC_CS_AS NULL,
PRIMARY KEY (chn)
)
insert into @pytable values('吖', 'A')
insert into @pytable values('八', 'B')
insert into @pytable values('嚓', 'C')
insert into @pytable values(' 数据库服务器每天凌晨两点进行数据库备份,同时对5天前的数据库备份文件进行删除,不然的话就会把硬盘给撑爆的
windows的日志里给出信息:
SQL Server Scheduled Job 'DB 维护计划“数据库维护计划1”的 DB 备份作业。' (0x2DA54A5BBEFC2B4A874428B91602C52A) - Status: 失败 - Invoked on: 2005-09-09 01:00:00 - Message: 作业失败。
  调度 28 (第 1 调度) 唤醒调用了该作业。最后运行的步骤是第 1 步(第 1 步)。
sql server里给出的日志:
sqlmaint.exe failed [SQLSTATE 42000]
相关的微软给出的kb
http://support.microsoft.com/?kbid=288577
http://support.microsoft.com/kb/303292/EN-US/
好像讲得一头雾水。
后来才发现是原来那些要备份的数据库中,其中有一个是脱机的,结果导致不能把它备份,也不能把它过期的删除掉,没办法,只好把它重新朕机上了。


sql server 2000以前的版本,例如7.0一般不存在多个版本,只有标准版跟桌面版,用户如果不清楚该装什么版本的话,可按安装上的安装先决条件指示安装,一般在WIN2000 服务器版上装标准版,其他的系统装桌面版的就可以;而SQL Server 2000安装问题就比较大,时常见问题有如下:
(1)配置服务器时中断.
(2)注册 ActiveX 时中断.
(3)显示到100%的时候中断.
(4)提示:command line option syntax error, type command /? for help,继续安装,最后在配置服务器的时候出现:无法找到动态链接SQLUNIRL.DLL于指定的路径……
(5)以前进行的程序创建了挂起的文件操作,运行安装程序前,必须重新启动
(1)(2)(3)的解决办法:
提醒:为避免误操作,先备份注册表和数据库进不了SQL Server 2000,可以备份 Program FilesMicrosoft SQL ServerMSSQLData 文件夹的文件.
1、先把SQL Server卸载(卸载不掉也没有关系,继续下面的操作)
2、把Microsoft SQL Server文件夹整个删掉。
3、运行注册表,删除如下项:
HKEY_CURRENT_USERSoftwareMicrosoftMicrosoft SQL Server
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft SQL Server
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSSQLServer
4、需要的话就重新启动系统
5、重新安装
另外也可尝试单步运行安装 SQL Server 2000的方法:
1:放入 SQL Server 2000 光盘.
2:在"开始"--"运行"键入 "F:x86setup.exe k=dbg" (F是光盘)
注意:
一、不同的操作系统支持的SQL Server 2000版本以及对硬件的要求。
Windows 2000 Server可以安装SQL Server 2000的任何版本.
Windows 2000 Professional只能安装SQL Server 2000的个人版、开发版、评估版、MCDE
二、
SQL Server 2000各版本以及对硬件的要求。
(4)的解决办法
因为安装文件的路径(完整路径)里有中文.
比如 c:SQLSERVER中文企业版
改成 c:SQLSERVER
(5)的解决办法
a、重启机器,再进行安装,如果发现还有该错误,请按下面步骤
b、在开始->运行中输入regedit
c、到HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession Manager 位置
d、选择文件->倒出,保存
e、在右边窗口右击PendingFileRenameOperations,选择删除,然后确认
f、重启安装,问题解决
-------------------------------------------------------
我将提出一个挑战,谁能用SQLSEERVER提出计算素数最好的方法,
我用了一个新的特点CTE和某些TSQL实现,但均不理想,前者(CTE)有限制,而后者(TSQL)产生一百万个素数用了7分种
你可以干的更好么?
这儿是我的一些代码段落
(TSQL实现)
set nocount on
declare @prime table (prime int not null primary key)
--insert into @prime values (2)
--insert into @prime values (3)
--insert into @prime values (5)
--insert into @prime values (7)
--insert into @prime values (11)
declare @number int, @pc int
set @number = 13
set @pc = 1
while @pc < 1000000
begin
if not exists (select 1 from @prime where @number % prime = 0 and prime < sqrt(@number) )
begin
insert into @prime select @number
set @pc = @pc 1
end
set @number = @number
case when @number %2 = 1 then 2
when @number %3 = 2 then 2
when @number %5 = 4 then 2
when @number %7 = 6 then 2
when @number  = 10 then 2
else 1 end
end
select @pc

(CTE实现)
with seq
as( select 13 number
union all
select s.number
case when s.number %2 = 1 then 2
when s.number %3 = 2 then 2
when s.number %5 = 4 then 2
when s.number %7 = 6 then 2
when s.number  = 10 then 2
else 1 end
from seq s
where number < 32767
)
, prime as (
select s.number
from seq s
where not exists ( select 1 from seq s2 where s2.number < s.number and (s.number) % s2.number = 0)
)
select *
from prime
option (MAXRECURSION 32767)


原始表如下格式:
Class CallDate CallCount
1     2005-8-8 40
1     2005-8-7 6
2     2005-8-8 77
3     2005-8-9 33
3     2005-8-8 9
3     2005-8-7 21
根据Class的值,按日期分别统计出CallCount1,CallCount2,CallCount3。
当该日期无记录时值为0
要求合并成如下格式:
CallDate  CallCount1  CallCount2  CallCount3
2005-8-9  0       0       33
2005-8-8  40      77      9
2005-8-7  6       0       21
--创建测试环境
Create table T (Class varchar(2),CallDate datetime, CallCount int)
insert into T select '1','2005-8-8',40
union all select '1','2005-8-7',6
union all select '2','2005-8-8',77
union all select '3','2005-8-9',33
union all select '3','2005-8-8',9
union all select '3','2005-8-7',21
--动态SQL
declare @s varchar(8000)
set @s='select CallDate '
select @s=@s ',[CallCount' Class ']=sum(case when Class=''' Class ''' then CallCount else 0 end)'
from T
group by Class
set @s=@s ' from T group by CallDate order by CallDate desc '
exec(@s)
--结果
CallDate CallCount1 CallCount2 CallCount3
------------------------------------------------------ ----------- ----------- -----------
2005-08-09 00:00:00.000 0 0 33
2005-08-08 00:00:00.000 40 77 9
2005-08-07 00:00:00.000 6 0 21
--删除测试环境
drop table T


标签:[!--infotagslink--]

您可能感兴趣的文章: