动态表名的查询SQL

更新时间:2023-06-22 12:45:20 阅读: 评论:0

动态表名的查询SQL CREATE TABLE [dbo].[TB_Ur](
[ID] [int] NOT NULL,
[Name] [varchar](50) NOT NULL,
[Score] [varchar](50) NULL,
) ON [PRIMARY]
INSERT INTO [dbo].[TB_Ur]
([ID],[Name] ,[Score])行尸走肉什么时候更新
VALUES (1,'Lucy','');
INSERT INTO [dbo].[TB_Ur]
([ID],[Name] ,[Score])
VALUES (1,'Lili','');
INSERT INTO [dbo].[TB_Ur]
([ID],[Name] ,[Score])
上海艺考培训VALUES (1,'Jack','');
declare @exesql nvarchar(1000);
declare @table varchar(50);
love to be loved by you
t @table='TB_Ur';
t @exesql='SELECT *  FROM [dbo].'+@table;
execute sp_executesql @exesql
declare @exesql nvarchar(1000);
declare @table varchar(50);
t @table='TB_Ur';
t @exesql='update [dbo].'+@table+' t Score=''Good''';
execute sp_executesql @exesql
过程 sp_executesql,参数类型必须为 'ntext/nchar/nvarchar'
hot>运营商英文另外的例⼦:
DECLARE @IntVariable int;
DECLARE @SQLString nvarchar(500);
DECLARE @ParmDefinition nvarchar(500);
/* Build the SQL string one time.*/
SET @SQLString =goole翻译
N'SELECT * FROM AdventureWorks.HumanResources.Employee
WHERE ManagerID = @ManagerID';
SET @ParmDefinition = tinyint';
/* Execute the string with the first parameter value. */
SET @IntVariable = 197;
muzak
EXECUTE sp_executesql @SQLString, @ParmDefinition,
@ManagerID = @IntVariable;
/* Execute the same string with the cond parameter value. */
SET @IntVariable = 109;
EXECUTE sp_executesql @SQLString, @ParmDefinition,
@ManagerID = @IntVariable;
--------------------------------------------------------------------
DECLARE @IntVariable int;
DECLARE @SQLString nvarchar(500);
DECLARE @ParmDefinition nvarchar(500);
DECLARE @max_title varchar(30);
SET @IntVariable = 197;
SET @SQLString = N'SELECT @max_titleOUT = max(Title)
台风英文FROM AdventureWorks.HumanResources.Employee
深圳的翻译公司WHERE ManagerID = @level';
SET @ParmDefinition = tinyint, @max_titleOUT varchar(30) OUTPUT';
EXECUTE sp_executesql @SQLString, @ParmDefinition, @level = @IntVariable, @max_titleOUT=@max_title OUTPUT; SELECT @max_title;
-----------------------------------------------------------
筷子兄弟 老男孩歌词更多的解释请参考微软帮助⽂档。

本文发布于:2023-06-22 12:45:20,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1013496.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:男孩   兄弟   表名
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图