I have a call to the name of the Code database field name, and I'm trying to select it using the variable name, as shown below:
Declare @var1 = [Code] (SELECT @var1 FROM [VoucherType] WHERE [DeletedBy] IS NULL AND [AutoID] = 1)
SQL seems to interpret @var1 as a string, not a field in my database, how can I do it this way @var1 recognized as the name of the [Code] field instead of the string, possibly without any select or if.
source share