SP with table valued parameters

  • Hi,

    I have a parent stored procedure which is calling the child stored procedure. The procedures are using table valued parameters. Before calling the child sp, I want to put the check that If the data is available in that variable then only execute that child sp.

    I have a parent sp name saveproduct_QP

    and it is calling savepricing_QP

    for that child sp, they assign some table valued parameters

    exec savepricing_QP

    @productdetails = @productdetails

    @Orderdetails = @orderdetails

    @customerId = @customerid output

    suppose if want keep some check condition for this. i.e. if data is exists in that parameter then only call that child sp

    what I have to keep the if clause

    I wrote like this

    IF (IF EXISTS (SELECT 1 FROM @ProductDetails) OR IF EXISTS (SELECT 1 FROM @OrderDetails)

    begin

    exec savepricing_QP

    End

    Is this works?

    What will happen by using If exists (select 1 from @ProductDetails)

    Shall I use iF EXISTS (select * from @ProductDetails)

    Which one right? And what is the difference b/n select 1 from tablevaluedparameter and select * from tablevaluedparameter.

    Please let me know. I appreciate your help.

    Thanks

  • ramana3327 (3/31/2014)


    Hi,

    I have a parent stored procedure which is calling the child stored procedure. The procedures are using table valued parameters. Before calling the child sp, I want to put the check that If the data is available in that variable then only execute that child sp.

    I have a parent sp name saveproduct_QP

    and it is calling savepricing_QP

    for that child sp, they assign some table valued parameters

    exec savepricing_QP

    @productdetails = @productdetails

    @Orderdetails = @orderdetails

    @customerId = @customerid output

    suppose if want keep some check condition for this. i.e. if data is exists in that parameter then only call that child sp

    what I have to keep the if clause

    I wrote like this

    IF (IF EXISTS (SELECT 1 FROM @ProductDetails) OR IF EXISTS (SELECT 1 FROM @OrderDetails)

    begin

    exec savepricing_QP

    End

    Is this works?

    What will happen by using If exists (select 1 from @ProductDetails)

    Shall I use iF EXISTS (select * from @ProductDetails)

    Which one right? And what is the difference b/n select 1 from tablevaluedparameter and select * from tablevaluedparameter.

    Please let me know. I appreciate your help.

    Thanks

    While most of your question is just noise to the actual question and lacks a lot of information I think you are asking if you should use

    IF EXISTS(select 1 from TVP)

    Instead of

    IF EXISTS(select * from TVP)

    There is no difference at all. They both do exactly the same thing.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

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

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