 |
|
 |
|
Next: I can not return the rows affected just using
|
| Author |
Message |
External

Since: Jan 31, 2005 Posts: 4
|
(Msg. 1) Posted: Mon Feb 21, 2005 4:35 pm
Post subject: Temp tables and SP Archived from groups: microsoft>public>sqlserver>programming (more info?)
|
|
|
Hi,
I have a StoredProcedure 'ProfitSP' in different databases and the ProfitSP
is same in each database.
If I execute ProfitSP as:
it works fine!
But if I try to create a temp table and then execute the same, it gives me
error as:
"Implicit conversion from data type sql_variant to datetime is not allowed.
Use the convert function to run this query."
---------------------------------------------------------
CREATE PROCEDURE dbo.ProfitSPAll (@OrderStartDate datetime, @OrderEndDate
datetime)
AS
create table #ProfitSPAllSites
( OrderYear datetime,
OrderMonth datetime,
Discount decimal(18,2),
Total decimal(18,2),
Profit decimal(18,2)
)
insert into #ProfitSPAllSites
Exec DB1.dbo.ProfitAll @OrderStartDate, @OrderEndDate
select * from #ProfitAll
GO
---------------------------------------------------------
I am using temp table because I have to execute SP's from different sites
and generate a report using MS Reporting Services (and I like temp tables). I
have used temp tables earlier but never had problems with 'datetime'. I tried
using CONVERT function but still didn't got it to work.
I will appreciate if you can let me know how to get past this datetime
problem. Thanks in advance. >> Stay informed about: Temp tables and SP |
|
| Back to top |
|
 |  |
External

Since: May 25, 2004 Posts: 67
|
(Msg. 2) Posted: Mon Feb 21, 2005 7:40 pm
Post subject: Re: Temp tables and SP [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Can you post the code of one of the ProfitAll stored procedures? Are the
OrderYear or OrderMonth columns sql_variant for some reason? Also, why are
these seperate columns? Why not use a single DATETIME or SMALLDATETIME
column for that data?
--
Adam Machanic
SQL Server MVP
<a rel="nofollow" style='text-decoration: none;' href="http://www.sqljunkies.com/weblog/amachanic" target="_blank">http://www.sqljunkies.com/weblog/amachanic</a>
--
"GJ" wrote in message
> Hi,
>
> I have a StoredProcedure 'ProfitSP' in different databases and the
ProfitSP
> is same in each database.
>
> If I execute ProfitSP as:
> it works fine!
>
> But if I try to create a temp table and then execute the same, it gives me
> error as:
> "Implicit conversion from data type sql_variant to datetime is not
allowed.
> Use the convert function to run this query."
>
> ---------------------------------------------------------
> datetime)
> AS
> create table #ProfitSPAllSites
> ( OrderYear datetime,
> OrderMonth datetime,
> Discount decimal(18,2),
> Total decimal(18,2),
> Profit decimal(18,2)
> )
> insert into #ProfitSPAllSites
> select * from #ProfitAll
> GO
> ---------------------------------------------------------
>
> I am using temp table because I have to execute SP's from different sites
> and generate a report using MS Reporting Services (and I like temp
tables). I
> have used temp tables earlier but never had problems with 'datetime'. I
tried
> using CONVERT function but still didn't got it to work.
>
> I will appreciate if you can let me know how to get past this datetime
> problem. Thanks in advance. >> Stay informed about: Temp tables and SP |
|
| Back to top |
|
 |  |
External

Since: Jan 31, 2005 Posts: 4
|
(Msg. 3) Posted: Mon Feb 21, 2005 7:40 pm
Post subject: Re: Temp tables and SP [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
No... orderyear and OrderMonth are datetime also...
and the code for each database is same as temp table... here it is:
CREATE PROCEDURE dbo.ProfitAll (@OrderStartDate datetime, @OrderEndDate
datetime)
AS
SELECT
a3.OrderYear,
a3.OrderMonth,
sum(a3.CMDiscount) AS Discount,
sum(a3.DebitTotal) AS Total,
sum(IsNull(a3.ProductRev,0) - IsNull(a3.COGoods,0)) AS Profit
FROM
(.... code...
DATEPART(Year, dbo.PRR.OrderDate) AS OrderYear,
DATEPART(Month, dbo.PRR.OrderDate) AS OrderMonthNum,
DATENAME(Month, dbo.PRR.OrderDate) AS OrderMonth
.... code...
)
GO
and PRR.Orderdate is defined in table design as smalldatetime of size 4. I
changed all passing parameters datetype as 'smalldatetime' but still the same
error.
These are seperate columns because my manager wants seperate columns for
month name and year name in the report.
Thanks for your consideration.
"Adam Machanic" wrote:
> Can you post the code of one of the ProfitAll stored procedures? Are the
> OrderYear or OrderMonth columns sql_variant for some reason? Also, why are
> these seperate columns? Why not use a single DATETIME or SMALLDATETIME
> column for that data?
>
>
> --
> Adam Machanic
> SQL Server MVP
<font color=purple> > <a rel="nofollow" style='text-decoration: none;' href="http://www.sqljunkies.com/weblog/amachanic</font" target="_blank">http://www.sqljunkies.com/weblog/amachanic</font</a>>
> --
>
>
> > Hi,
> >
> > I have a StoredProcedure 'ProfitSP' in different databases and the
> ProfitSP
> > is same in each database.
> >
> > If I execute ProfitSP as:
> > it works fine!
> >
> > But if I try to create a temp table and then execute the same, it gives me
> > error as:
> > "Implicit conversion from data type sql_variant to datetime is not
> allowed.
> > Use the convert function to run this query."
> >
> > ---------------------------------------------------------
> > datetime)
> > AS
> > create table #ProfitSPAllSites
> > ( OrderYear datetime,
> > OrderMonth datetime,
> > Discount decimal(18,2),
> > Total decimal(18,2),
> > Profit decimal(18,2)
> > )
> > insert into #ProfitSPAllSites
> > select * from #ProfitAll
> > GO
> > ---------------------------------------------------------
> >
> > I am using temp table because I have to execute SP's from different sites
> > and generate a report using MS Reporting Services (and I like temp
> tables). I
> > have used temp tables earlier but never had problems with 'datetime'. I
> tried
> > using CONVERT function but still didn't got it to work.
> >
> > I will appreciate if you can let me know how to get past this datetime
> > problem. Thanks in advance.
>
>
> >> Stay informed about: Temp tables and SP |
|
| Back to top |
|
 |  |
External

Since: Sep 21, 2004 Posts: 118
|
(Msg. 4) Posted: Mon Feb 21, 2005 8:21 pm
Post subject: Re: Temp tables and SP [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
I'm confused that you are inserting into one table and selecting from
another (not even in example):
insert into #ProfitSPAllSites
Exec DB1.dbo.ProfitAll @OrderStartDate, @OrderEndDate
select * from #ProfitAll
--
David Gugick
Imceda Software
www.imceda.com >> Stay informed about: Temp tables and SP |
|
| Back to top |
|
 |  |
External

Since: Jan 31, 2005 Posts: 4
|
(Msg. 5) Posted: Mon Feb 21, 2005 8:21 pm
Post subject: Re: Temp tables and SP [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Hi David,
Sorry ... its a typo..
it should be..
insert into #ProfitSPAllSites
Exec DB1.dbo.ProfitAll @OrderStartDate, @OrderEndDate
select * from #ProfitSPAllSites
"David Gugick" wrote:
> I'm confused that you are inserting into one table and selecting from
> another (not even in example):
>
> insert into #ProfitSPAllSites
> select * from #ProfitAll
>
> --
> David Gugick
> Imceda Software
> <a rel="nofollow" style='text-decoration: none;' href="http://www.imceda.com" target="_blank">www.imceda.com</a>
>
> >> Stay informed about: Temp tables and SP |
|
| Back to top |
|
 |  |
External

Since: May 25, 2004 Posts: 67
|
(Msg. 6) Posted: Mon Feb 21, 2005 9:07 pm
Post subject: Re: Temp tables and SP [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
OrderYear and OrderMonth are not datetime. They're whatever the datatype
output by datepart is -- INT, I always assumed, but based on your error
possibly sql_variant. Check this out to see what you're actually doing when
you assign these INTs back to a datetime:
declare @blah datetime
set @blah = datepart(mm, getdate())
print @blah
Seperate them in the report code, not in your stored procedure.
--
Adam Machanic
SQL Server MVP
<a rel="nofollow" style='text-decoration: none;' href="http://www.sqljunkies.com/weblog/amachanic" target="_blank">http://www.sqljunkies.com/weblog/amachanic</a>
--
"GJ" wrote in message
> No... orderyear and OrderMonth are datetime also...
> and the code for each database is same as temp table... here it is:
>
> datetime)
> AS
> SELECT
> a3.OrderYear,
> a3.OrderMonth,
> sum(a3.CMDiscount) AS Discount,
> sum(a3.DebitTotal) AS Total,
> sum(IsNull(a3.ProductRev,0) - IsNull(a3.COGoods,0)) AS Profit
> FROM
> (.... code...
>
> DATEPART(Year, dbo.PRR.OrderDate) AS OrderYear,
> DATEPART(Month, dbo.PRR.OrderDate) AS OrderMonthNum,
> DATENAME(Month, dbo.PRR.OrderDate) AS OrderMonth
>
> .... code...
> )
> GO
>
> and PRR.Orderdate is defined in table design as smalldatetime of size 4.
I
> changed all passing parameters datetype as 'smalldatetime' but still the
same
> error.
>
> These are seperate columns because my manager wants seperate columns for
> month name and year name in the report.
>
>
> Thanks for your consideration.
>
> "Adam Machanic" wrote:
>
> > Can you post the code of one of the ProfitAll stored procedures? Are
the
> > OrderYear or OrderMonth columns sql_variant for some reason? Also, why
are
> > these seperate columns? Why not use a single DATETIME or SMALLDATETIME
> > column for that data?
> >
> >
> > --
> > Adam Machanic
> > SQL Server MVP
<font color=green> > > <a rel="nofollow" style='text-decoration: none;' href="http://www.sqljunkies.com/weblog/amachanic</font" target="_blank">http://www.sqljunkies.com/weblog/amachanic</font</a>>
> > --
> >
> >
> > > Hi,
> > >
> > > I have a StoredProcedure 'ProfitSP' in different databases and the
> > ProfitSP
> > > is same in each database.
> > >
> > > If I execute ProfitSP as:
> > > it works fine!
> > >
> > > But if I try to create a temp table and then execute the same, it
gives me
> > > error as:
> > > "Implicit conversion from data type sql_variant to datetime is not
> > allowed.
> > > Use the convert function to run this query."
> > >
> > > ---------------------------------------------------------
@OrderEndDate
> > > datetime)
> > > AS
> > > create table #ProfitSPAllSites
> > > ( OrderYear datetime,
> > > OrderMonth datetime,
> > > Discount decimal(18,2),
> > > Total decimal(18,2),
> > > Profit decimal(18,2)
> > > )
> > > insert into #ProfitSPAllSites
> > > select * from #ProfitAll
> > > GO
> > > ---------------------------------------------------------
> > >
> > > I am using temp table because I have to execute SP's from different
sites
> > > and generate a report using MS Reporting Services (and I like temp
> > tables). I
> > > have used temp tables earlier but never had problems with 'datetime'.
I
> > tried
> > > using CONVERT function but still didn't got it to work.
> > >
> > > I will appreciate if you can let me know how to get past this datetime
> > > problem. Thanks in advance.
> >
> >
> > >> Stay informed about: Temp tables and SP |
|
| Back to top |
|
 |  |
| Related Topics: | Temp Tables and Joins - I'm trying to create a temp table and insert columns from two different tables into it using an outter join. I keep getting an "Invalid column name" error for the column coming from the joined table. Are there any potential complications I shou...
"connection" for temp tables - I thought I knew what "connection" meant, but now I guess i don't. Two books told me that temp tables were not destroyed until the "connection" ends. I created temp tables in one SQL script, and tried to build a view from them in a...
viewing #temp tables - I using .Net 2008 to troubleshoot my SQL Server stored procedures. It allows me to connect to a Sql Server database and step into the stored procs and troubleshoot. It is a very usefull tool. However, when doing that, I would like to be able to view..
limit on # of temp tables? - I have a script that creates several (4+) temp tables. However, when I run the script, it acts like the first two exist but the latter ones do not. I use the code SELECT TABLE_NAME FROM tempdb.INFORMATION_SCHEMA.TABLES WHERE [TABLE_NAME] LIKE '%#%'....
Temp tables, can client tell the difference - Hi, I have a stored procedure, called by a client application, that returns a recordset. If I use a temp table within the procedure, the client gives an error, but there is no error if I write procedure code, returning exactly the same records but.. |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|