sqlserver 存储过程 使用guid的相关记录

来源:互联网 发布:java开发架构设计 编辑:程序博客网 时间:2024/06/04 23:30


1. 存储的值若为guid 但指定的列格式若为varchar之类的话  传入guid的varchar字符串查询查询不到


2. 需要更改列的格式为uniqueidentifier 存储过程的变量也改为uniqueidentifier


3.判断是否需要添加条件 传入空的guid 但不能为字符串类型


USE [commonSystem]GO/****** Object:  StoredProcedure [dbo].[a]    Script Date: 05/09/2017 18:11:42 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author:<Author,,Name>-- Create date: <Create Date,,>-- Description:<Description,,>-- =============================================ALTER PROCEDURE [dbo].[a]-- Add the parameters for the stored procedure here@start datetime,@end    datetime,@type int,@Companyid int,@articleid uniqueidentifierASBEGINdeclare @sint    intdeclare @eint    intset @sint=DATEPART(day,@start)set @eint=DATEdiff(DAY,@start,@end)SET NOCOUNT ON;  set language N'Simplified Chinese' ;WITH TT AS (             SELECT   number            FROM     master..spt_values            WHERE    type = 'P'                    AND number BETWEEN @sint-1 AND @eint             )select b.[date],        [count]=isnull(a.[count],0),        monday=datename(WEEKDAY, b.[date]) from (    select showdata,            [count]=COUNT(actshowId)    from actshowinfo     where showtype=@type     and Companyid=    case when @Companyid <>0                            then @Companyid                        else Companyid                  end    and articleid=    case when @articleid <>'00000000-0000-0000-0000-000000000000'                            then @articleid                        else articleid                  end        group by showdata    ) a    right join (    select [date]=DATEADD(DAY,TT.number,@start)    from TT    ) b    ON a.showdata=b.[date]END




调用



USE [commonSystem]GODECLARE@return_value intdeclare @guid uniqueidentifier select @guid = CAST('00000000-0000-0000-0000-000000000000' as uniqueidentifier)EXEC@return_value = [dbo].[a]@start = N'2017-05-01',@end = N'2017-05-31',@type=1,@articleid=@guid,@companyid=0SELECT'Return Value' = @return_valueGO


0 0