这个查询能用变量写出来吗?
16lz
2021-01-22
Can this query be written with out using variable?
这个查询能用变量写出来吗?
Basically what I need is an ID of some thing from some table for inserting a new record. Right now I'm doing it by storing that ID in variable and then using it.
基本上,我需要的是从某个表中插入新记录的某个东西的ID。现在我将ID存储在变量中然后使用它。
DECLARE @store_num char(4);
SELECT @store_num = [store_no] FROM store WHERE (store_name = 'Rocky Mountain Produce');
INSERT INTO [ITD640_B].[dbo].[employee]
([employee_no]
,[employee_fname]
,[employee_lname]
,[store_no])
VALUES
(123456
,'YourFirstName'
,'YourLastName'
,@store_num);
3 个解决方案
#1
5
INSERT INTO [ITD640_B].[dbo].[employee]
([employee_no]
,[employee_fname]
,[employee_lname]
,[store_no])
SELECT
123456
,'YourFirstName'
,'YourLastName'
,[store_no]
FROM
store
WHERE
store_name = 'Rocky Mountain Produce';
更多相关文章
- SQLSERVER 中表变量与临时表
- 在Delete From语句中带有别名的表变量。
- ORACLE-SQL:定义并使用多字符串变量
- 我不能使用PHP和SQL在循环之间传递变量?
- 手把手教你mysql(十五)游标变量流程控制
- AppScan安全问题解决方案
- 将变量(表名,数据)传递给python mysqld查询
- PLSQL乱码解决方案
- PLSQL并非所有变量都已绑定