如果在其他条件下如何从表中选择特定Id [英] How Can I Select Perticular Id From Table In If Else Condition

查看:94
本文介绍了如果在其他条件下如何从表中选择特定Id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在if else条件中从表中选择特定的id

how can i select perticular id from table in if else condition

推荐答案

而不是IF-ELSE你需要使用CASE [ ^ ]

这是关于主题的CodeProject文章简单使用SQL CASE表达式 [ ^ ]。

Instead of IF-ELSE you need to use CASE[^]
Here is a CodeProject article on the subject A Simple Use of SQL CASE Expression[^].
会员10694442说:
Member 10694442 said:

&我想对所有4000行执行此操作

& i want to do this for all 4000 rows

请注意,如果不使用 WHERE [ ^ ]子句然后它将影响表格上的每一行 - 更多信息 here [ ^ ]。



在你的情况下,这可行:

Be aware that if you don't filter your SQL query using a WHERE[^] clause then it will affect every row on the table - more information here[^].

In your case this would work:

select CASE WHEN [close] > [ref] THEN 'Buy' ELSE 'Sell' END
from YourTable

请注意,我用方括号包围了列名,因为 close 是SQL Server的保留字之一[ ^ ]。最好避免将保留字用作列名或变量名。

Notice that I have surrounded the column names with square brackets because close is one of SQL Server's reserved words[^]. It is best practise to avoid using reserved words as column or variable names.


这篇关于如果在其他条件下如何从表中选择特定Id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆