sql²éÕÒij¸ö×Ö·û´®µÚN´Î³öÏÖµÄλÖõĺ¯Êý(תÌû)
if exists(select 1 from sysobjects where name='char_index')
drop function char_index
create function char_index(@string varchar(8000),@char varchar(10),@index smallint)
--@string:´ý²éÕÒ×Ö·û´®£¬@index:²éÕÒλÖÃ
returns smallint
as
begin
declare
@i tinyint,--µ±Ç°ÕÒµ½µÚ@i¸ö
@position tinyint--ËùÔÚλÖÃ
set @position=@index;
set @i=0;
while charindex(@char,@string,@position)>0
begin
set @position=charindex(@char,@string,@position)+1;
set @i=@i+1;
if @i=@index
begin
return @position-1;
end
end
return 0;--0±íʾδÕÒµ½
end
select dbo.char_index('sdf_dsf_dfgdg_ertr_erte','f_',2)
--ÈçºÎ²éÕÒij¸ö×Ö·û´®µÚN´Î³öÏÖµÄλÖÃ,
--±ÈÈç:×Ö·û´®"sdf_dsf_dfgdg_ertr_erte",Òª²éÕÒ"f_"µÚ¶þ´Î³öÏÖµÄλÖÃ
if object_id('f_findstr') is not null
drop function f_findstr
go
create function f_findstr(@s varchar(8000),@find varchar(10),@index int)
returns int
as
begin
declare @startindex int
set @startindex=0
while @index>0
begin
if charindex(@find,@s,@startindex)>0
set @startindex=charindex(@find,@s,@startindex+1)
set @index=@index-1
end
return @startindex
end
go
select dbo.f_findstr('sdf_dsf_dfgdg_ertr_erte','f_',2)
use test
go
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[F_Str]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[F_Str]
GO
CREATE FUNCTION dbo.F_Str(
@s varchar(8000),
@pos int,
@split varchar(10)
)RETURNS int
AS
BEGIN
IF @s IS NULL RETURN(NULL)
DECLARE @splitlen int,@i int
SELECT @splitlen=LEN(@split+'a')-2,@i=0
WHILE @pos>1 AND CHARINDEX(@split,@s+@split)>0
SELECT @pos=@pos-1,@i=@i+CHARINDEX(@split,@s+@split)+@splitlen,
&nb
Ïà¹ØÎĵµ£º
¸ÕÅöµ½Õâ¸öÎÊÌâʱ£¬ÒÔΪÊÇÓ¦Ó÷þÎñÆ÷ºÍÊý¾Ý¿â·þÎñÆ÷ûÁ¬Í¨£¬²éÁ˰ëÌìµÄÍøÂç½á¹ûÍøÉÏÒ»²é£¬¸úSQL Server 2005Óйأ¬ÄãÌ«ÑôµÄ£¡
¿ªÊ¼²Ëµ¥-SQLServer2005-ÅäÖù¤¾ß-SQL Server Configuration Manager-SQLserver2005ÍøÂçÅäÖÃ-MSSQLSERVERµÄÐÒé-Ë«»÷TCP/IPÐÒé
°ÑIP¸Ä³Éµ±Ç°Ê¹Óõ쬵±È»£¬¶Ë¿ÚҲҪȷ±£ ......
»Ö¸´Ä£Ê½£¨Recovery Model£©Ö¼ÔÚ¿ØÖÆÊÂÎñÈÕ־ά»¤¡£»Ö¸´Ä£Ê½ËµÃ÷Á˹¤×÷¶ªÊ§µÄ·çÏÕ£¬ÄÜ·ñ»Ö¸´µ½Ê±µã£¿
SQL ServerÊý¾Ý¿âÓÐÈýÖÖ»Ö¸´Ä£Ê½£º¼òµ¥»Ö¸´Ä£Ê½¡¢ÍêÕû»Ö¸´Ä£Ê½ºÍ´óÈÝÁ¿ÈÕÖ¾»Ö¸´Ä£Ê½¡£
Ïà¶ÔÓÚ¼òµ¥»Ö¸´Ä£Ê½¶øÑÔ£¬ÍêÕû»Ö¸´Ä£Ê½ºÍ´óÈÝÁ¿ÈÕÖ¾»Ö¸´Ä£Ê½ÌṩÁ˸üÇ¿µÄÊý¾Ý±£»¤¹¦ÄÜ¡£ÕâЩ»Ö¸´Ä£Ê½¶¼ÊÇ»ùÓÚ±¸·ÝÊÂÎñÈÕÖ ......
from: http://blog.163.com/ck275601774/blog/static/1230468012009631113559291/
--ÈÕÆÚת»»²ÎÊý
select CONVERT(varchar,getdate(),120)
--2009-03-15 15:10:02
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
--20090315151201
select CONVERT(varchar(12) , getdate ......
½¨±í£º
CREATE TABLE [DB.dbo].tableName
(Stud_id int CONSTRAINT constraintName1 not null primary key,
Name nvarchar(5) not null,
Birthday datetime,
Gender nchar(1),
Telcode char(12),
Zipcode char(6) CONSTRAINT constraintName2 CHECK(zipcode like [ ......
BEGIN TRANSACTION--¿ªÊ¼ÊÂÎñ
DECLARE @errorSun INT --¶¨Òå´íÎó¼ÆÊýÆ÷
SET @errorSun=0 --û´íΪ0
UPDATE a SET id=232 WHERE a=1 --ÊÂÎñ²Ù×÷SQLÓï¾ä
SET @errorSun=@errorSun+@@ERROR --ÀÛ¼ÆÊÇ·ñÓдí
UPDATE aa SET id=2 WHERE a=1 --ÊÂÎñ²Ù×÷SQLÓï¾ä
SET @errorSun=@errorSun+@@ERROR --ÀÛ¼ÆÊÇ·ñÓдí
I ......