在SQL Server中插入存储过程? [英] Insert stored procedure in SQL Server?

查看:179
本文介绍了在SQL Server中插入存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将列名作为字符串值传递给SQL Server中的INSERT STORED PROCEDURE?



Is it Possible pass the column name as string value to INSERT STORED PROCEDURE in SQL Server?

INSERT INTO SwipeHrs(EmpID,EmpCode,Dept_Id,Team_Id,At_Date,@UConcateSHColumn,@UConcatePTColumn)VALUES (@empid,@empcode,@dept,@team,@CurrentDate,@UConcateSH,@UConcatePT)

推荐答案

是... ish。

你不能这样做直接,因为列名在更高级别被解析,所以你不能直接传递一个变量。

但是......如果你建立一个字符串,你可以这样做:

Yes...ish.
You can't do it directly, as the column names are parsed at a higher level, so you can't directly pass a variable.
But...you can do it if you build up a string:
DECLARE @COLNAME NVARCHAR(MAX)
SET @COLNAME = 'MyColumn'
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = 'SELECT ' + @COLNAME + ' FROM MyTable'
EXEC (@SQL)



这会选择列,但INSERT是相同的过程


This selects the column, but INSERT is the same procedure


您好OriginalGriff





但是,我有62个列..如何检查并将列传递到那里?
Hi OriginalGriff


But, i have 62 Columns.. how do i Check and pass the columns to there?


这篇关于在SQL Server中插入存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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