0

I want to insert those values also which have version null and and for version null I don't have status.

I am getting all data from datatable to procedure table type and then how do I check that the incoming data has version null or not?

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[uspInsertFilterData]
     @sqlDataTable SqlTableType READONLY
AS
BEGIN
    IF (@sqlDataTable.Version IS NOT NULL OR @sqlDataTable.Version != '')
    BEGIN
        INSERT INTO FilterCombination (Version, HotFix, Resourcetype, Language)
            (SELECT 
                 t1.Product, t1.Version, t1.HotFix, t1.Resourcetype, 
                 t1.Language 
             FROM
                 @sqlDataTable t1, Product_Version_Mapping t2  
             WHERE
                 t1.Product = t2.Product 
                 AND t1.Version = t2.Version  
                 AND t2.Status = 'Correct')
    END
    ELSE
    BEGIN
        INSERT INTO FilterCombination (Product, Version, HotFix, Resourcetype, Language)   
            (SELECT 
                 t1.Product, t1.Version, t1.HotFix, t1.Resourcetype, t1.Language 
             FROM
                 @sqlDataTable t1, Product_Version_Mapping t2  
             WHERE
                 t1.Product = t2.Product);
    END
END

This query is not working. Please help

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 2
    It's difficult to understand what you want. Also please expand on "not working". This doesn't tell us anything. – Nick.Mc Feb 20 '16 at 13:11
  • You don't specify your problem, but this is suspicious: `@sqlDataTable.Version is NOT NULL or @sqlDataTable.Version != ''`. I think you need an `AND` instead of `OR`. – Hans Kesting Feb 20 '16 at 13:27
  • Also, the first insert lists **four** columns in your `INSERT INTO` table name, but you provide **FIVE** columns in your `SELECT` ..... – marc_s Feb 20 '16 at 13:30

1 Answers1

0

For checking null values, you can use NULLIF like so...

IF NULLIF(@PreviousStartDate, '') IS NULL

Please refer below link.

Check if a parameter is null or empty in a stored procedure

Community
  • 1
  • 1
Mr doubt
  • 51
  • 1
  • 10
  • 42