Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Please edit this to me i am in urgent need of this

Author  Topic 

khasim76
Starting Member

35 Posts

Posted - 2008-09-18 : 13:51:04
Create procedure usp_getInfo(@sql,@v_dt datetime, @o_company_name varchar(255)

As

Begin
declare @sql varchar(500)
@sql=Select 'conm' Into @o_company_name
From issuer c,eq_company b

Where C.issuer_id = b.company_key

And valid_to >= v_dt

And valid_from <= v_dt
order by issuer_id
EXEC ( @sql )

End

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-18 : 13:52:02
Yikes! Why would you want to write this kind of bad code?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 13:53:07
what are you trying to do. can you explain?
Go to Top of Page

khasim76
Starting Member

35 Posts

Posted - 2008-09-18 : 13:57:22

I AM TRYING TO GENERALISE THIS QUERY BY WRITING STORED_PROCEDURE..plz help me out i am new to store procedures

select C.issuer_id, C.issuer_name,COMPANY_VERSION,valid_to,valid_from
from issuer C, eq_company b
where C.issuer_id = b.company_key
AND issuer_id = 109799
and valid_to >=getdate()
And valid_from <=getdate()
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 14:01:36
quote:
Originally posted by khasim76


I AM TRYING TO GENERALISE THIS QUERY BY WRITING STORED_PROCEDURE..plz help me out i am new to store procedures

select C.issuer_id, C.issuer_name,COMPANY_VERSION,valid_to,valid_from
from issuer C, eq_company b
where C.issuer_id = b.company_key
AND issuer_id = 109799
and valid_to >=getdate()
And valid_from <=getdate()


why are you using dynamic sql for that? didnt get purpose of that.
Go to Top of Page

khasim76
Starting Member

35 Posts

Posted - 2008-09-18 : 14:05:11
i am just new to store procedure i will explain in words
i have a table issuer
i have a table company
comapny has historical data
i want to write a stored procedure which will bring me the company name(which is a column) as per any requested date. say on 04/23/2004.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 14:10:00
something like below:-
Create procedure usp_getInfo
@v_dt datetime, @o_company_name varchar(255)

As

select C.issuer_id, C.issuer_name,COMPANY_VERSION,valid_to,valid_from
from issuer C, eq_company b
where C.issuer_id = b.company_key
AND issuer_id = 109799
and valid_to >=@v_dt
And valid_from <=@v_dt
and C.COMPANY_Name=@o_company_name
GO
Go to Top of Page

khasim76
Starting Member

35 Posts

Posted - 2008-09-18 : 14:20:37
Thanks for that, it ran well. but how ot test it plz let me know
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 14:26:23
quote:
Originally posted by khasim76

Thanks for that, it ran well. but how ot test it plz let me know


exec usp_getInfo @v_dt=somedatevalue,@o_company_name=somecomapnyname in your database
Go to Top of Page

khasim76
Starting Member

35 Posts

Posted - 2008-09-18 : 14:28:36
Thank you veery much
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 14:35:16
quote:
Originally posted by khasim76

Thank you veery much


welcome
Go to Top of Page
   

- Advertisement -