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
 Creating Stored Procedure with Temp table

Author  Topic 

Kanne
Starting Member

2 Posts

Posted - 2014-09-09 : 15:38:20
Hi

I need to create a Stored Procedure in SQL server which passes 6 input parameters Eg:

ALTER procedure [dbo].[sp_extract_Missing_Price]
@DisplayStart datetime,
@yearStart datetime,
@quarterStart datetime,
@monthStart datetime,
@index int
as

Once I declare the attributes I need to create a Temp table and update the data in it.Please help creating temp table

Once I have created the Temp table following query I need to run

SELECT date FROM #tempTable
WHERE #temp.date NOT IN (SELECT date FROM mytable WHERE mytable.date IN (list-of-input-attributes) and index = @index)

The above query might return null result or a date .

In case null return output as "DataNotMissing"
In case not null return date and string as "Datamissing"

Any help in this regard is highly appreciated.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-09-09 : 15:45:40
Here's an example:
create table #temp (column1 int, column2 varchar(30), column3 bigint, column4 datetime)

You haven't provided enough info for us to help you load the data into it.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Kanne
Starting Member

2 Posts

Posted - 2014-09-09 : 17:55:17
Well I am new to creating stored proc in SQL server.

The idea is to create this SP to accept 6 parameters as shown below

Populate the temp table with these data and then run the below query

SELECT date FROM #tempTable
WHERE #temp.date NOT IN (SELECT date FROM mytable WHERE mytable.date IN (comma separated input attributes) and index = @index)

Now return the following to the application



In case null dataset return output as "DataNotMissing"
In case not null dataset return date and string as "Datamissing"

Appreciate an example structure



quote:
Originally posted by tkizer

Here's an example:
create table #temp (column1 int, column2 varchar(30), column3 bigint, column4 datetime)

You haven't provided enough info for us to help you load the data into it.


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-09-10 : 13:03:44
Populate the temp table with the values of the input parameters? That doesn't make any practical sense.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -