开发者

How to find the value if it is exist in the table? [closed]

It's dif开发者_StackOverflowficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜