Hello friends,
Suppose I have 5000 records and I want to perform an operation on it.
I want to use 2 columns in sub-query for all above records.
Example:
Way-1:- DECLARE @TempSizeID INT;
- SET @NewSizeID = ISNULL((SELECT ISNULL(id,0) FROM tb_sizes WHERE StoreID=@NewStoreID),0);
-
- IF(@NewSizeID = 0)
- BEGIN
- -- sub-query for insert data
- SET @NewSizeID = SCOPE_IDENTITY()
- END
- ELSE
- BEGIN
- IF NOT EXISTS (SELECT ISNULL(SizeID,0) FROM tb_ProductColorSizeMapping WHERE ProductID = @NewProductID AND SizeID = @NewSizeID)
- BEGIN
- -- sub-query for insert mapping data
- END
- END
Way-2:- DECLARE @TempSizeID INT;
-
- IF(@ISNULL((SELECT ISNULL(id,0) FROM tb_sizes WHERE StoreID=@NewStoreID),0) = 0)
- BEGIN
- -- sub-query for insert data
- SET @NewSizeID = SCOPE_IDENTITY()
- END
- ELSE
- BEGIN
- IF NOT EXISTS (SELECT ISNULL(SizeID,0) FROM tb_ProductColorSizeMapping WHERE ProductID = @NewProductID AND SizeID =
- (ISNULL((SELECT ISNULL(id,0) FROM tb_sizes WHERE StoreID=@NewStoreID),0)))
- BEGIN
- -- sub-query for insert mapping data
- END
- END
In way-1 it number of queries is less but it takes storage to store id
In way-2 it number of queries is more but and not store id
Can anybody suggest me which is fast?.