I am running some sql that take the info from a temporary table and puts it into the permanent table. I got it from a step by step guide written 3 years ago, and the person who wrote it is long gone. it states to use this sql here.
我正在运行一些sql,它从临时表中获取信息并将其放入永久表中。我是从3年前写的一步一步的指南中得到的,写这篇文章的人早就不见了。它声明在这里使用这个SQL。
declare @Password nvarchar(100);
set @Password ='rewards';
if not exists(select 1 from sys.openkeys where key_name = 'Sym_UserPassData'
and database_name = db_name()) OPEN SYMMETRIC KEY Sym_UserPassData DECRYPTION BY
CERTIFICATE UserPassTables with password='asbpass71509new';
INSERT INTO [User] (Username, [Password], AllowChange, ForceChange, FullName,
SalesRep, OpenLink, UserProfileID, LastUpdatedBy,UserEmail)
(SELECT Username,EncryptByKey(Key_GUID('Sym_UserPassData'),@Password),
AllowChange, ForceChange, FullName, SalesRep, [OpenLink ], UserProfileID,
LastUpdateBy, UserEmail FROM TempUsers)
and then after that it says the following
之后它说了以下内容
If the password is unique for each row, take the set @Password = ‘Password’; off and replace the @Password with [Password].
如果每行的密码都是唯一的,请设置@Password ='密码';关闭并用[密码]替换@Password。
so at first I just changed the 2nd line so it said
所以起初我只是更改了第二行,所以它说
declare @Password nvarchar(100);
set [Password]
...
But that gave me an error with the password column so then i changed it to:
但这给了我一个密码列的错误,所以我把它改为:
declare [Password] nvarchar(100);
set [Password]
if not exists(select 1 from sys.openkeys where key_name = 'Sym_UserPassData'
and database_name = db_name()) OPEN SYMMETRIC KEY Sym_UserPassData DECRYPTION BY
CERTIFICATE UserPassTables with password='asbpass71509new';
INSERT INTO [User] (Username, [Password], AllowChange, ForceChange, FullName,
SalesRep, OpenLink, UserProfileID, LastUpdatedBy,UserEmail)
(SELECT Username,EncryptByKey(Key_GUID('Sym_UserPassData'),[Password]),
AllowChange, ForceChange, FullName, SalesRep, [OpenLink ], UserProfileID,
LastUpdateBy, UserEmail FROM TempUsers)
and that is what gave me the error:
这就是给我错误的原因:
nvarchar is not a recognized cursor option
Does anyone know what I am missing? If i can provide any other info I will do my best to do so.
有谁知道我错过了什么?如果我能提供任何其他信息,我会尽我所能。
Thank you to anyone who is able to help with this.
感谢能够提供帮助的任何人。
2 个解决方案
#1
23
You have to declare variables with the @
sign before the names. So this is correct:
您必须在名称前使用@符号声明变量。所以这是正确的:
declare @Password nvarchar(100);
set @Password ='rewards';
This is NOT correct:
这不正确:
declare [Password] nvarchar(100);
set [Password] ='rewards';
I think the problem is with your variable declaration. See this article: http://www.databasejournal.com/features/mssql/article.php/3087431/T-SQL-Programming-Part-1---Defining-Variables-and-IFELSE-logic.htm
我认为问题在于您的变量声明。请参阅此文章:http://www.databasejournal.com/features/mssql/article.php/3087431/T-SQL-Programming-Part-1---Defining-Variables-and-IFELSE-logic.htm
#2
1
If [Password] is a column in TempUsers it might mean this.
如果[密码]是TempUsers中的一列,则可能意味着这一点。
if not exists(select 1 from sys.openkeys where key_name = 'Sym_UserPassData'
and database_name = db_name()) OPEN SYMMETRIC KEY Sym_UserPassData DECRYPTION BY
CERTIFICATE UserPassTables with password='asbpass71509new';
INSERT INTO [User] (Username, [Password], AllowChange, ForceChange, FullName,
SalesRep, OpenLink, UserProfileID, LastUpdatedBy,UserEmail)
(SELECT Username,EncryptByKey(Key_GUID('Sym_UserPassData'),[Password]),
AllowChange, ForceChange, FullName, SalesRep, [OpenLink ], UserProfileID,
LastUpdateBy, UserEmail FROM TempUsers)
#1
23
You have to declare variables with the @
sign before the names. So this is correct:
您必须在名称前使用@符号声明变量。所以这是正确的:
declare @Password nvarchar(100);
set @Password ='rewards';
This is NOT correct:
这不正确:
declare [Password] nvarchar(100);
set [Password] ='rewards';
I think the problem is with your variable declaration. See this article: http://www.databasejournal.com/features/mssql/article.php/3087431/T-SQL-Programming-Part-1---Defining-Variables-and-IFELSE-logic.htm
我认为问题在于您的变量声明。请参阅此文章:http://www.databasejournal.com/features/mssql/article.php/3087431/T-SQL-Programming-Part-1---Defining-Variables-and-IFELSE-logic.htm
#2
1
If [Password] is a column in TempUsers it might mean this.
如果[密码]是TempUsers中的一列,则可能意味着这一点。
if not exists(select 1 from sys.openkeys where key_name = 'Sym_UserPassData'
and database_name = db_name()) OPEN SYMMETRIC KEY Sym_UserPassData DECRYPTION BY
CERTIFICATE UserPassTables with password='asbpass71509new';
INSERT INTO [User] (Username, [Password], AllowChange, ForceChange, FullName,
SalesRep, OpenLink, UserProfileID, LastUpdatedBy,UserEmail)
(SELECT Username,EncryptByKey(Key_GUID('Sym_UserPassData'),[Password]),
AllowChange, ForceChange, FullName, SalesRep, [OpenLink ], UserProfileID,
LastUpdateBy, UserEmail FROM TempUsers)