Reputation: 135
I have a little problem.
I'm SELECTING From a table. I want to see a value what is just used only in one point of my workflow. Before that no value here.
But, if no result, then my "result" is NULL
. And thats not good for me.
I mean, if I write
SELECT myValue FROM myTable WHERE asd = 'thisIs'
when myValue
is NULL
in the table, then my result is NULL
. Thats okay.
when no results found, then my result is NULL
too. Thats not okay.
If no result I have do different function. How can I separate these ?
|MyValue|
---|-------|
1 |NULL |
---|-------|
|MyValue|
---|-------|
|MyValue|
---|-------|
1 |Hello |
---|-------|
In the first and third case I have to call an Update function, in the second case I have to call an Insert function.
But the result what my SP is sending back in the first and second case is NULL too.
Thank you for your help in advance.
Upvotes: 0
Views: 158
Reputation: 121
You can count number of rows found after select records query. if count is greater or equal to one you have to run update query else insert query as selected records are empty.
Upvotes: 0
Reputation: 2768
As I understand you want to do something like this:
IF EXISTS (
SELECT myValue FROM myTable WHERE asd = 'thisIs'
)
BEGIN
SELECT myValue FROM myTable WHERE asd = 'thisIs'
END
ELSE
BEGIN
EXEC SomeOtherCode
END
Upvotes: 1