﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / creating procudre for dynamic table / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 21 May 2013 18:59:40 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: creating procudre for dynamic table</title><link>http://www.sqlservercentral.com/Forums/Topic1370673-392-1.aspx</link><description>[quote][b]raghuldrag (10/10/2012)[/b][hr]if you dnt mind would please  explain the "sp_executesql" what is the use??and what should be do there??[/quote]Check this link on the site [url]http://www.sqlservercentral.com/Forums/Topic1244180-1292-1.aspx[/url].There are few more just google "sp_executesql vs EXEC"...Pedro</description><pubDate>Thu, 11 Oct 2012 00:38:44 GMT</pubDate><dc:creator>PiMané</dc:creator></item><item><title>RE: creating procudre for dynamic table</title><link>http://www.sqlservercentral.com/Forums/Topic1370673-392-1.aspx</link><description>if you dnt mind would please  explain the "sp_executesql" what is the use??and what should be do there??</description><pubDate>Wed, 10 Oct 2012 22:48:52 GMT</pubDate><dc:creator>raghuldrag</dc:creator></item><item><title>RE: creating procudre for dynamic table</title><link>http://www.sqlservercentral.com/Forums/Topic1370673-392-1.aspx</link><description>It'sEXEC GetData 't1', 'name'GO... without parentheses.</description><pubDate>Wed, 10 Oct 2012 06:35:29 GMT</pubDate><dc:creator>Arthur Kirchner</dc:creator></item><item><title>RE: creating procudre for dynamic table</title><link>http://www.sqlservercentral.com/Forums/Topic1370673-392-1.aspx</link><description>while executing dis query error occured on output:exec</description><pubDate>Wed, 10 Oct 2012 05:46:11 GMT</pubDate><dc:creator>raghuldrag</dc:creator></item><item><title>RE: creating procudre for dynamic table</title><link>http://www.sqlservercentral.com/Forums/Topic1370673-392-1.aspx</link><description>[quote][b]ChrisM@home (10/10/2012)[/b][hr]You could also use dynamic sql for this.[/quote][code="sql"]CREATE PROCEDURE GetData(@TableName NVARCHAR(120), @Columns NVARCHAR(255))AS BEGIN	DECLARE @Query AS NVARCHAR(MAX)	SET @Query = 'SELECT ' + @Columns + ' FROM ' + @TableName	EXEC sp_executesql @QueryENDGOEXEC GetData('t1', 'name')GO[/code]In this example you can specify the columns you want on the output...Pedro</description><pubDate>Wed, 10 Oct 2012 04:08:10 GMT</pubDate><dc:creator>PiMané</dc:creator></item><item><title>RE: creating procudre for dynamic table</title><link>http://www.sqlservercentral.com/Forums/Topic1370673-392-1.aspx</link><description>[quote][b]raghuldrag (10/9/2012)[/b][hr]Hi friends,   create tab T1(name varchar(22),age numeric(22))   create tab T2(name varchar(22),age numeric(22))insert into t1 values('ram',22)insert into t1 values('am',26)insert into t1 values('sam',28)insert into t1 values('bam',23)insert into t1 values('kam',21)insert into t2 values('yam',22)insert into t2 values('dam',22)insert into t2 values('gam',22)insert into t2 values('pam',22)now i need to create procedure if am giving the table name has inputshow the output of name only!!!!exec pro(t1)expecting output:NAMEramamsambamkam[/quote]exec pro(t1) won't work, this will: exec pro('t1')Assuming the table name is captured into parameter Tablename, your stored procedure could look something like this:IF @Tablename = 'T1'    SELECT DISTINCT Name FROM t1ELSE IF @Tablename = 'T2'    SELECT DISTINCT Name FROM t2You could also use dynamic sql for this.</description><pubDate>Wed, 10 Oct 2012 01:03:31 GMT</pubDate><dc:creator>ChrisM@home</dc:creator></item><item><title>creating procudre for dynamic table</title><link>http://www.sqlservercentral.com/Forums/Topic1370673-392-1.aspx</link><description>Hi friends,   create tab T1(name varchar(22),age numeric(22))   create tab T2(name varchar(22),age numeric(22))insert into t1 values('ram',22)insert into t1 values('am',26)insert into t1 values('sam',28)insert into t1 values('bam',23)insert into t1 values('kam',21)insert into t2 values('yam',22)insert into t2 values('dam',22)insert into t2 values('gam',22)insert into t2 values('pam',22)now i need to create procedure if am giving the table name has inputshow the output of name only!!!!exec pro(t1)expecting output:NAMEramamsambamkam</description><pubDate>Tue, 09 Oct 2012 22:58:51 GMT</pubDate><dc:creator>raghuldrag</dc:creator></item></channel></rss>