Results 1 to 4 of 4

Thread: Help on select statement

  1. #1
    DmitriyK Guest

    Help on select statement

    Hi,

    I am running the following statement within a stored procedure:

    select * into #tempCust from customer where account = @_chrAcct
    select * from #tempCust

    The trick is this: if @_chrAcct is NULL I don't want to have it as part of the where statement (so all I want is "select * into #tempCust from customer" ). I cannot use exec(..) because it creates another process and I won't be able to get to my temporary table. I also cannot create permanent or global temporary table for my purposes.

    Thanks to whoever can solve this puzzle for me.

  2. #2
    Guest

    Help on select statement (reply)

    In the stored procedure just put a if statment checking if @_chrAcct is null (or check for datalength(@_chrAcct) is 0)

    That should do the trick.


    ------------
    DmitriyK at 3/21/00 4:38:00 PM

    Hi,

    I am running the following statement within a stored procedure:

    select * into #tempCust from customer where account = @_chrAcct
    select * from #tempCust

    The trick is this: if @_chrAcct is NULL I don't want to have it as part of the where statement (so all I want is "select * into #tempCust from customer" ). I cannot use exec(..) because it creates another process and I won't be able to get to my temporary table. I also cannot create permanent or global temporary table for my purposes.

    Thanks to whoever can solve this puzzle for me.

  3. #3
    DmitriyK Guest

    Help on select statement (reply)

    I am not being specific enough...@_chrAcct is just one parameter, I have about 10 parameters altogether. I can't have that many IF statements.


    ------------
    at 3/22/00 9:47:33 AM

    In the stored procedure just put a if statment checking if @_chrAcct is null (or check for datalength(@_chrAcct) is 0)

    That should do the trick.


    ------------
    DmitriyK at 3/21/00 4:38:00 PM

    Hi,

    I am running the following statement within a stored procedure:

    select * into #tempCust from customer where account = @_chrAcct
    select * from #tempCust

    The trick is this: if @_chrAcct is NULL I don't want to have it as part of the where statement (so all I want is "select * into #tempCust from customer" ). I cannot use exec(..) because it creates another process and I won't be able to get to my temporary table. I also cannot create permanent or global temporary table for my purposes.

    Thanks to whoever can solve this puzzle for me.

  4. #4
    Bob Guest

    Help on select statement (reply)

    Check to see if @_chrAcct is null. If it is run one select statement, if it isn't run another one. On another note, do you realize SELECT INTO is a nonlogged operation and your transaction logs are useless for a restore??


    ------------
    DmitriyK at 3/22/00 9:49:42 AM

    I am not being specific enough...@_chrAcct is just one parameter, I have about 10 parameters altogether. I can't have that many IF statements.


    ------------
    at 3/22/00 9:47:33 AM

    In the stored procedure just put a if statment checking if @_chrAcct is null (or check for datalength(@_chrAcct) is 0)

    That should do the trick.


    ------------
    DmitriyK at 3/21/00 4:38:00 PM

    Hi,

    I am running the following statement within a stored procedure:

    select * into #tempCust from customer where account = @_chrAcct
    select * from #tempCust

    The trick is this: if @_chrAcct is NULL I don't want to have it as part of the where statement (so all I want is "select * into #tempCust from customer" ). I cannot use exec(..) because it creates another process and I won't be able to get to my temporary table. I also cannot create permanent or global temporary table for my purposes.

    Thanks to whoever can solve this puzzle for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •