if condition not working

  • Hi

    I have given only date parameters . All other null , but it is not going in If condition

    -- =============================================

    Alter PROCEDURE [dbo].[Ind_sp_CabProfitability]

    @frDate date,

    @toDate date,

    @VCode nvarchar(15) = null,

    @VName nvarchar(100) = null,

    @CCode nvarchar(15) = null,

    @CName nvarchar(100) = null,

    @CGroup nvarchar(15) = null

    as

    begin

    If @VCode is Null And @VName is Null And @CCode is null And @CName is null And @CGroup is null

    Begin

    SELECT

    T1.U_VendCode as "Vendor Code",T1.U_CabNo,T1.U_VendName as "Vendor Name",

    T1.U_CustCode as "Cust Code",T1.U_CustName as "Cust Name",T1.U_ItemCode,Max(T1.U_ItemName)

    where T0.U_DATE BETWEEN @frDate and @toDate

    End

    End

  • Is that your entire stored procedure or did you strip something out?  It looks to me like you are missing a FROM.

    The above is all just my opinion on what you should do. 
    As with all advice you find on a random internet forum - you shouldn't blindly follow it.  Always test on a test server to see if there is negative side effects before making changes to live!
    I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply