1樓:匿名使用者
var nid,i : integer;(先申明變數)sql.clear;
sql.add('select deptnum,deptname,deptdesc from department where deptid=:nid') ;
parambyname('nid').asinteger := i;
prepare ;
if active = false then active := true ;
其中i值是變數;
2樓:飛絮流爽
直接在程式裡寫成變數就可以了,變數要有賦值,否則會出錯例如vb裡這樣寫
sql = "select * from product where id='" & trim(text1.text) & "'"
rst4.open sql, con1, 1, 1條件表示id=text1的text的值
3樓:
用儲存過程可以做到
我寫了乙個簡單的例子如下
if exists(select * from sysobjects where name = 'proc_select')
drop proc proc_selectgo--建立儲存過程
create proc proc_select@stuid int--使用者編號
asselect * from stuinfo where stuid = @stuid--變數
goexec proc_select @stuid=1--1 為學生編號 由使用者輸入
go--你看能滿足你的要求不
4樓:百王朋度
用儲存過程,
create procedure 儲存過程名(@引數名 型別
)select * from table1 where (列名)=@引數
在程式中用儲存過程,別直接用sql語句就行了。
如何使用sql語句修改表內的資料
5樓:匿名使用者
修改表中內容
修改用到update語句,語句格式為:update 表名稱 set 列名稱 = 新值 where 列名稱 = 某值
即 update 員工表 set 部門id=01 where 員工id=0004
sql聯合主鍵
create table 表名 (欄位名1 int not null,
欄位名2 nvarchar(13) not null primary key (欄位名1, 欄位名2),
欄位名3…………
欄位名n………… )
擴充套件資料
主鍵是資料庫表的乙個重要屬性,建立主鍵可以避免表中存在完全相同的記錄,也就是說主鍵在一張表中的記錄值是唯一的。 建立主鍵有兩種方法:一種是在資料庫提供的gui環境中建立,另一種是通過sql語句執行建立,下面分別介紹。
在資料庫提供的gui環境中建立(以sql7為例)。輸入表資訊後按ctrl鍵同時選中多行,然後點上面的主鍵按鈕就行了。
通過sql語句執行建立。又分兩種,一是在建表語句中直接寫,二是建表之後更改表結構。
在建表語句中直接寫:
create table 表名 (欄位名1 int not null,
欄位名2 nvarchar(13) not null primary key (欄位名1, 欄位名2),
欄位名3…………
欄位名n………… )
6樓:匿名使用者
/*修改員工表中員工編號為「0004」的員工所屬部門編號為01表名:員工表
列名:員工編號,部門編號*/
update 員工表 set 部門編號=01 --如果01是字元型,則加上單引號
where 員工編號='0004'
不知道是不是你要的答案
sql怎麼用查詢結果作為條件進行查詢 10
7樓:浪小客
1、查詢資料庫表的所有欄位並直接使用select語句。從資料庫表中選擇*。
2、查詢資料庫表的part部分字段,可以使用select field命令,從資料庫表中選擇欄位名稱。
3、根據條件查詢,使用後面的條件,加上從資料庫表中選擇條件名稱。
4、使用distinct命令查詢資料庫字段記錄中的非重複結果,從資料庫中選擇不同的欄位名稱。
5、查詢資料庫表前面的資料,可以使用top命令,從資料庫表中選擇頂部編號*。
8樓:匿名使用者
巢狀select語句也叫子查詢,乙個 select 語句的查詢結果能夠作為另乙個語句的輸入值。子查詢不但能夠出現在where子句中,也能夠出現在from子句中,作為乙個臨時表使用,也能夠出現在select list中,作為乙個欄位值來返回。
1、單行子查詢 :單行子查詢是指子查詢的返回結果只有一行資料。當主查詢語句的條件語句中引用子查詢結果時可用單行比較符號(=, >, <, >=, <=, <>)來進行比較。
例:select ename,deptno,sal from emp
where deptno=(select deptno from dept where loc='new york');
2、多行子查詢:多行子查詢即是子查詢的返回結果是多行資料。當主查詢語句的條件語句中引用子查詢結果時必須用多行比較符號(in,all,any)來進行比較。
其中,in的含義是匹配子查詢結果中的任乙個值即可("in" 操作符,能夠測試某個值是否在乙個列表中),all則必須要符合子查詢的所有值才可,any要符合子查詢結果的任何乙個值即可。而且須注意all 和any 操作符不能單獨使用,而只能與單行比較符(=、>、< 、>= 、<= 、<>)結合使用。 例:
1).多行子查詢使用in操作符號例子:
查詢選修了老師名叫rona(假設唯一)的學生名字
sql> select stname from student
where stid in(selectdistinct stid from score where teid=(select teid from teacher where tename='rona'));
查詢所有部門編號為a的資料: select ename,job,sal from emp
where deptno in ( select deptno from dept where dname like 'a%');
2).多行子查詢使用all操作符號例子:查詢有一門以上的成績高於kaka的最高成績的學生的名字: sql> select stname from student
where stid in(select distinct stid from score where score >all(select score from score where stid=(select stid from student where stname= 'kaka') )); 3). 多行子查詢使用any操作符號例子:查詢有一門以上的成績高於kaka的任何一門成績的學生的名字:
sql> select stname from student
where stid in(select distinct stid from score where score >any(select score from score where stid=(select stid from student where stname='kaka')));
希望能幫到你
9樓:時針樓
像你這種情況用 in或not in 關鍵字比較好
10樓:射手小小王
select * from table_b where people_name in (select people_name from table_a);
SQL資料庫查詢
sql出錯的解決方法是給子查詢加別名,如下 string sqlstr select top 15 from select from news order by id desc as a where kind yes and id not in select top v id from select...
資料庫sql查詢語言
很簡單啊 其實每次修改金額 你可以理解為插入 而不是更新 看看下面的例子 id號 金額 原始金額flag 我覺得如果是一樣表 至少要有這樣或者類似這樣的設計方式 flag 有三個值 0 1 2.0 表示初始金額 1表示修改過的金額 2表示最近一次修改的金額 這樣每次修改金額其實是追加了一條資料 將這...
sql資料查詢,批量修改sql資料庫查詢出來的資料
第一種寫法,比較好理解 declare num int set num 0 select case when rowindex in 1,2 then num num score else num num 2 score endfrom select row number over order by...
用sql查詢如何開啟access資料庫
select from opendatasource microsoft.jet.oledb.4.0 data source d nyy nyyadmin web bonus 20100714.dat user id admin password abc123 表1 select from open...
sybase資料庫SQL語句 查詢賬號資訊?
2 查詢每個登陸賬號對應有哪些資料賬號。select name from 每個資料庫名稱 sysusers where suid suser id 賬號名 3 查詢資料賬號屬於哪個許可權組。sp helpuser 使用者名稱 具體要看資料庫中的表名字。sybase資料庫,查詢登陸所有登陸使用者,且查...