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
 Get and Count Returned Table

Author  Topic 

kekewong
Starting Member

6 Posts

Posted - 2010-06-09 : 13:18:48
Hi, i have a function which will lists the individual days between 2 date ranges, assume that the function name is "fnGetDatesInRange".

The thing i want to do is , i am trying to do is declare a Table variable in store procedure and get the returned table from the function. Below is some example:

DECLARE @TotalDays int
DECLARE @ReturnedTable Table

Set @ReturnedTable = (SELECT Dt from fnGetDatesInRange('01 Jan 2010', '31 Jan 2010')) -- Some how it doesn't return the table and set into my variable

Set @TotalDays = Count (@ReturnedTable) -- Not sure if this works

I tried to run individually by using :
SELECT Dt from fnGetDatesInRange('01 Jan 2010', '31 Jan 2010') and it does return a table, but i cannot store into the variable and count the number of display.

I am new to SQL script so i wish some one can guide me a bit. Thank you.

Kind Regards,
kekewong

GhantaBro
Posting Yak Master

215 Posts

Posted - 2010-06-09 : 14:31:50
quote:
Originally posted by kekewong

Hi, i have a function which will lists the individual days between 2 date ranges, assume that the function name is "fnGetDatesInRange".

The thing i want to do is , i am trying to do is declare a Table variable in store procedure and get the returned table from the function. Below is some example:

DECLARE @TotalDays int
DECLARE @ReturnedTable Table

Set @ReturnedTable = (SELECT Dt from fnGetDatesInRange('01 Jan 2010', '31 Jan 2010')) -- Some how it doesn't return the table and set into my variable

Set @TotalDays = Count (@ReturnedTable) -- Not sure if this works

I tried to run individually by using :
SELECT Dt from fnGetDatesInRange('01 Jan 2010', '31 Jan 2010') and it does return a table, but i cannot store into the variable and count the number of display.

I am new to SQL script so i wish some one can guide me a bit. Thank you.

Kind Regards,
kekewong




There is no data type called table in sql... you need to use varchar for table name... I am not sure what you are trying to do, but if you are trying to create the table based on the name you pass then you have use that variable in the function to create the table with that variable name...
Go to Top of Page
   

- Advertisement -