更新存储过程MS SQL后检查记录值

时间:2017-03-16 16:15:49

标签: sql-server

执行存储过程

EXEC dbo.Web_update
 @hHomeEmail = 'me@me.com',
 @pPassword = 'XXXXX',
 @mMemberID = '123456'

存储过程

 UPDATE Member 
 SET pass_w = @pPassword, 
 HomeEmail = @hHomeEmail
 WHERE MemberID=@mMemberID;

我想在UPDATE之后检查HomeEmail和pass_w的值,如果为NULL则不返回由于该调用而返回的布尔值。

----------更新----------

USE [Test]
GO
/****** Object:  StoredProcedure [dbo].[Web_update] Script Date: 03/21/2017 12:37:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      
-- Create date: 
-- Description: 
-- =============================================
ALTER PROCEDURE [dbo].[Web_update] 
    -- Add the parameters for the stored procedure here

    @hHomeEmail nvarchar(10) = NULL,
    @MemberNo nvarchar(10) = NULL,
    @pPassword nvarchar(10) = NULL,
    @mMemberID INT

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    UPDATE Member SET pass_w = @pPassword, HomeEmail = @hHomeEmail WHERE MemberID=@mMemberID;

    -- Insert statements for procedure here
    SELECT CASE WHEN EXISTS ( SELECT 1 FROM member WHERE MemberID=@mMemberID AND pass_w = NULL OR HomeEmail= NULL)

        THEN CAST(1 AS BIT)
            ELSE CAST(0 AS BIT) END


END

现在我想检查一下:

pass_w = NULL

OR

pass_w =''

OR

HomeEmail = NULL

OR

HomeEmail =''

如果其中一个是CAST(1 AS BIT)

ELSE CAST(0 AS BIT)

1 个答案:

答案 0 :(得分:0)

您可以向存储过程添加输出参数:

 /*Checked directory content: yes, Pictures directory exists*/
    File Ls[]=getFilesDir().listFiles();

    Uri MyUri = FileProvider.getUriForFile(this, "com.example.root.capture.fileprovider", new File(getFilesDir().toString() + "/Pictures/sorgente.jpg"));

    OutputStream OS;
    try {
        OS = getContentResolver().openOutputStream(MyUri);
    } catch(IOException ioe)
    {
        /*Always there*/
        return;
    }