Table Name:Peishain(Warehouse receiving ticket)
Table Structure: innumber char (8), indate datetime, intype char (12 ),Cangwei char (12 ),Pihao char (18), inweight decimal (9, 2), remark varchar (80)
The dynamic statements built in SQL Server are as follows (find the statements that meet the conditions based on the value of cangwei, one condition cannot run, if multiple conditions are more troublesome ):
Declare @ sqlstring varchar (200)
Declare @ cangwei varchar (12)
Set @ cangwei = 'b1'
Set @ sqlstring = 'select * From peishain where cangwei ='+ @ Cangwei
Exec (@ sqlstring)
Why is it always prompted:
Server: Message 207, level 16, status 3, Row 1
The column 'b1 'is invalid.
You may not be able to solve this problem. Please take a look at it. Please have a ready-made dynamic creation statement for comprehensive query conditions.ProgramCodeShare with me (INT, datetime, Char, and Other types are involved in the where condition). Thank you!