Can we see an example of the data you are talking about? Also, would this blank value be what you are inserting? If so, I would think isntead of inserting and deleting it, simply not insert if the value in question is blank.
IF EXISTS ( SELECT columnsListGoesHere FROM myTable WHERE myColumnName = 'valueGoesHere' )
BEGIN
-- do here what you want
END
ELSE
BEGIN
-- write statements what you want in case of non-existence
END
ying87
Member
37 Points
61 Posts
In procedure delete the row if the value is empty
Nov 06, 2012 02:28 PM|LINK
hi,
I have a procedure which will run the sql query and the result of the query may contain the empty value.
How to use IF-ELSE statement to do the checking and delete the row if empty value found before insert the result into the table?
bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: In procedure delete the row if the value is empty
Nov 06, 2012 02:32 PM|LINK
Can we see an example of the data you are talking about? Also, would this blank value be what you are inserting? If so, I would think isntead of inserting and deleting it, simply not insert if the value in question is blank.
Lannie
Contributor
3738 Points
728 Posts
Re: In procedure delete the row if the value is empty
Nov 06, 2012 03:34 PM|LINK
what database are you using??
capabilities and syntax vary from database to database
ying87
Member
37 Points
61 Posts
Re: In procedure delete the row if the value is empty
Nov 07, 2012 12:48 PM|LINK
hi,
I'm using oracle, below here is the sql query and result:
SQL: select module , line , type , sum(qty) qty , date_in from tableA group by rollup (date_in, date_out, category, line); RESULT: Module Line Type Qty Date_in M1 218 Type_A 323 10/30/2012 M1 218 Type_B 165 10/30/2012 M1 218 488 10/30/2012 M1 220 Type_A 102 10/30/2012 M1 220 Type_B 205 10/30/2012 M1 220 307 10/30/2012 M1 795 10/30/2012In the result, it contain an empty value at column 3 and row 3, so i want to delete the row and make it become like below:
If i did not use "gruup by rollup", my result will more than 100 record.
Lannie
Contributor
3738 Points
728 Posts
Re: In procedure delete the row if the value is empty
Nov 07, 2012 06:29 PM|LINK
group by rollup gives subtotals and some column cells in the subtotal row do become blank.
since you are ROLLING UP on multiple variables
anil.india
Contributor
2613 Points
453 Posts
Re: In procedure delete the row if the value is empty
Nov 08, 2012 11:36 AM|LINK
IF EXISTS ( SELECT columnsListGoesHere FROM myTable WHERE myColumnName = 'valueGoesHere' ) BEGIN -- do here what you want END ELSE BEGIN -- write statements what you want in case of non-existence ENDcodepattern.net/blog ||@AnilAwadh