當前位置:首頁 » 編程語言 » sql的if賦值
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql的if賦值

發布時間: 2022-05-22 15:24:16

sql中if語句的用法。我想在if判斷語句中比較一個表中的兩個屬性的值,例如比較table.mat

定義變數
declare @a int
declare @b int
賦值
select @a=欄位1,@b=欄位2
from 表名
where 條件
比較
if(@a>@b)
begin
--邏輯
end

Ⅱ sql if語句判斷

這個有點模糊,2個表沒有主外鍵關系嗎? 那怎麼比用A中哪條記錄的shi值和B中哪條記錄的shi值比? 如果是A查出一條記錄的shl和B中查出一條記錄的shl比,你可以寫個存儲過程,把2條記錄查出的shl分別賦值給2個變數,然後再寫if判斷

Ⅲ pl/sql 的if else語句後必須有賦值語句么

if else只是一個判斷語句,用法正確就可以了,沒有必要一定跟賦值語句。

delcare
anumber:=0;
bnumber:=1;
begin
ifa>bthen
dbms_output.putline('a>b');
else
dbms_output.putline('a<b');
endif;
end;
/

Ⅳ SQL中如何把條件判斷之後的值賦值給變數

declare@iasint

select@i=casewehn1>0then1else0end
select@i

if2>1
set@i=2
else
set@i=1
select@i

Ⅳ 用SQL語句中的IF語句編寫:

select 姓名,
case when 成績 < 60 then '不及格'
when 成績 >=60 and 成績 <70 then '及格'
when 成績 >=70 and 成績 <80 then '中等'
....
end as 等級 from 表

Ⅵ 如何用SQL代碼將動態查詢結果賦值給變數

1、首先最基本的賦值就是默認值了。

Ⅶ java中怎麼把sql查詢出的結果賦值給一個變數

理論上這樣賦值
User_Money=rst.getString("Money");
但你要考慮一下你的資料庫,如果username和Money不是一對一的關系,即一個名字對應三個Money,那麼你sql語句得到的將是值
如果使用下面語句
if(rst.next()){
User_Money=rst.getString("Money");//將得到第一個值
}
如果使用下面語句
while(rst.next()){ //有下一個值存在,while循環將繼續,那麼User_Money連續被賦值
User_Money=rst.getString("Money");//將得到第三個值
}

Ⅷ c#讀取SQL資料庫賦值給變數後退出if語句後無法用

這樣寫
String qp_dd;
String second_data;//第二個變數
SqlDataReader read = cmd.ExecuteReader();
if (read.Read())
{
qp_dd = read["qp_dd"].ToString();
textBox1.Text = qp_dd;
second_data=read["second_data"].ToString(); //第二個變數在資料庫中的欄位
if(條件判斷)

{
執行相關語句
}
}

Ⅸ sql 查詢所有滿足條件數據並賦值

我對樓上的回答,再稍作修改
redim gx(rs.recordcount)
dim i as integer
i=-1
while not rs.eof
i = i + 1
gx(i)=rs.Fields("cIWhCode").Value & ""
rs.movenext
wend