ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Pass (Send) Integer variable as Column Name to Select statement in SQL Server<p>Hi&nbsp;<a class="username" rel="nagaraju60">nagaraju60,</a></p> <p>You have to execute using Dymanic query.</p> <p>Check the below sample query.</p> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">CREATE TABLE TT_Screen( [Rack_Id] [int] NOT NULL, [Row_Name] [char](1) NOT NULL, [1] [varchar](5) NULL, [2] [varchar](5) NULL, [3] [varchar](5) NULL, [4] [varchar](5) NULL ) INSERT INTO TT_Screen VALUES(9,&#39;A&#39;,1,0,3,0) INSERT INTO TT_Screen VALUES(9,&#39;B&#39;,0,2,0,4) INSERT INTO TT_Screen VALUES(9,&#39;C&#39;,0,0,3,0) INSERT INTO TT_Screen VALUES(9,&#39;D&#39;,0,2,3,4) DECLARE @Rack_Id VARCHAR(10), @Row_Name char(1), @Column varchar(5) SET @Rack_Id = 9 SET @Row_Name = &#39;B&#39; SET @Column =&#39;3&#39; DECLARE @DynQuery nvarchar(1000) SET @DynQuery = N&#39;SELECT [&#39; + @Column + &#39;] FROM TT_Screen WHERE Row_Name = &#39;&#39;&#39;+@Row_Name+&#39;&#39;&#39; AND Rack_Id = &#39;&#39;&#39;+@Rack_Id+&#39;&#39;&#39;&#39; EXEC (@DynQuery) GO DECLARE @Rack_Id VARCHAR(10), @Row_Name char(1), @Column varchar(5) SET @Rack_Id = 9 SET @Row_Name = &#39;C&#39; SET @Column =&#39;3&#39; DECLARE @DynQuery nvarchar(1000) SET @DynQuery = N&#39;SELECT [&#39; + @Column + &#39;] FROM TT_Screen WHERE Row_Name = &#39;&#39;&#39;+@Row_Name+&#39;&#39;&#39; AND Rack_Id = &#39;&#39;&#39;+@Rack_Id+&#39;&#39;&#39;&#39; Exec (@DynQuery)</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <p>For first query output is 0.</p> <p>For second query output is 3.</p>https://www.aspforums.net:443/Threads/126630/Pass-Send-Integer-variable-as-Column-Name-to-Select-statement-in-SQL-Server/https://www.aspforums.net:443/Threads/126630/Pass-Send-Integer-variable-as-Column-Name-to-Select-statement-in-SQL-Server/Tue, 26 Mar 2019 07:53:26 GMT