Declare @ sqlTemp varchar (1000)
Declare @ wireType varchar (32)
The set @ sqlTemp='select' + @ wireType + '=wireType from wire_t where wireCode=010'
The exec (@ sqlTemp)
Select @ wireType
CodePudding user response:
- so sweet
Declare @ wireType varchar (32)
Select @ wireType=wireType from wire_t where wireCode=010
Select @ wireType
CodePudding user response:
Thank you for your reply, you this way no problem, I want to know where is the way I wrote wrong?CodePudding user response:
Don't @ wireType assignment, the default is null, the select @ wireType, of course, is the result of the null luo
Declare @ sqlTemp varchar (1000)
Declare @ wireType varchar (32)
The set @ wireType='XXXXXX'
The set @ sqlTemp='select' + @ wireType + '=wireType from wire_t where wireCode=010'
The EXEC (@ sqlTemp)
Select @ wireType
CodePudding user response:
declare @ sqlTemp varchar (1000)
Declare @ wireType varchar (32)
The SET @ wireType='1'
The set @ sqlTemp='select' + @ wireType + '=wireType from wire_t where wireCode=010'
PRINT @ sqlTemp
The exec (@ sqlTemp)
Select @ wireType
You'll know it in the code printed, the fifth line to add a PRINT, right on the second floor, @ wireType variable assignment, SQL query results
CodePudding user response:
Declare @ sqlTemp varchar (1000)The set @ sqlTemp='declare @ wireType varchar (32);
Select @ wireType=wireType from wire_t where wireCode=010;
Select '@ wireType="' + @ wireType '
The exec (@ sqlTemp)
CodePudding user response:
Exec (@ sqlTemp) in the parentheses variables can only be defined within the exec string, your mistake is not understand the problem of the exec variable scope