raghuldrag (10/9/2012)
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 input
show the output of name only!!!!
exec pro(t1)
expecting output:
NAME
ram
am
sam
bam
kam
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 t1
ELSE IF @Tablename = 'T2'
SELECT DISTINCT Name FROM t2
You could also use dynamic sql for this.
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]