Execute a dynamic SQL statement in SQL

zhaozj2021-02-16  90

CREATE procedure gethisData @maxdate int, @mindate int, @fieldname varchar (30) as beginDECLARE @strsql varchar (300) select @ strsql = 'select the date, time,' @ fieldname 'FROM OPENDATASOURCE (' 'SQLOLEDB' '' ',' 'Data Source = .; user ID = sa; password = 123' '' ') .shengli.dbo.hisdata where date> =' str (@Mindate) 'and date < str (@ MaxDate)

EXEC (@strsql) endGo

转载请注明原文地址:https://www.9cbs.com/read-11882.html

New Post(0)