How to find the value if it is exist in the table? [closed]
I created a SQL table called stock
. In that table are the fields itemcode
& netweight
. How can I get a message like "The Stock is Not Available" if the netweight field is zero for a particular item code?
That shouldn't be a database concern in the first place; the database's job is to store (wait for it) data. So the appropriate query is just:
select netweight from stock where itemcode = @itemcode
then it is a UI concern to do something like (for example)
someControl.Text = netweight > 0 ? netweight.ToString()
: "The Stock is Not Available";
However, if you must do it at the database, case
:
select case when netweight > 0 then convert(varchar(10), netweight)
else 'The Stock is Not Available' end as [netweight]
from stock where itemcode = @itemcode
select 'The Stock is Not Available'
from stock
where netweight = 0 and 'YOUR CONDITION'
This is what you can use in your stored procedure.
Please give more information about table and what you need to do if you want in detail..
精彩评论