From Denis blog I came to know recently that we are able to use sp_executesql without declaring the variables! It really sounded strange to me. I thought it to be one another bug :) So thought would dig deep into this and see what best I can conclude. --Dummy table schema Create table tblQuestion1 ( sno int identity, fname varchar(50) ) Go --Lets add some dummy records into the table Insert into tblQuestion1 values ('Alpha') Insert into tblQuestion1 values ('Beta') Insert into tblQuestion1 values ('Gamma') --So-called strange script Declare @strFetchData nvarchar(100) Select @strFetchData = 'Select * from tblQuestion1' Exec sp_executesql @alpha = @strFetchData If you have noticed we haven't declared @alpha in the script but SQL hasn't complained about it! I thought the easiest way to understand would be to go through sp_executesql procedure. Sp_helptext sp_executesql go Result - "(server internal)" … so its not a stored proc. I tried a
I write about things which I am passionate about.