Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Syntax error converting datetime from character string while calling a function Expand / Collapse
Author
Message
Posted Tuesday, June 26, 2012 6:08 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, June 27, 2012 1:02 AM
Points: 13, Visits: 10
Hi Friends,

I am trying to call a function (which returns month value when passing date as parameter ) in another query but it is resulting into

Syntax error converting datetime from character string.


select
(CASE WHEN (sht.mode='SI' Or sht.mode='AI') THEN (y3.[M_NAD_IND])
ELSE (y1.[M_NAD_IND])
end)as [Maxdate_Nad_IND],
max(b.shpdate) as [MAX_shpDate],
count(shipment)as Shp_Count

into #maxDate_swift
from allstat b
Left Join nad_new y1 on y1.adrno=b.Shipper
Left Join nad_new y3 on y3.adrno=b.consignee
left join shipmenttype sht on b.[type]=sht.[type]
where b.shpdate between (DATEADD(m, -6, @year + '-' + + '-01'))
and (DATEADD(dd, -1, @year + '-' + 'select * from mon_allstat('+ b.shpdate + ')' + '-01'))
group by (CASE WHEN (sht.mode='SI' Or sht.mode='AI') THEN (y3.[M_NAD_IND])
ELSE (y1.[M_NAD_IND])
end)
--@month

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

Pls. help



Kindest Regards,

Neetu Sharma
Post #1321173
Posted Tuesday, June 26, 2012 6:16 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 9:33 AM
Points: 6,754, Visits: 12,854
DATEADD(dd, -1, @year + '-' + 'select * from mon_allstat('+ b.shpdate + ')' + '-01')

This isn't valid syntax.

Can you post the structure of function mon_allstat()?


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1321176
Posted Tuesday, June 26, 2012 10:06 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, June 27, 2012 1:02 AM
Points: 13, Visits: 10
Hi

create FUNCTION mon_allstat(@sdate datetime)
RETURNS TABLE
AS
RETURN
(
SELECT distinct month(shpdate)as ddate from allstat where
[allstat].shpDate=@sdate
)



Kindest Regards,

Neetu Sharma
Post #1321661
Posted Wednesday, June 27, 2012 1:58 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 9:33 AM
Points: 6,754, Visits: 12,854
Thanks. Resolving the expensive iTVF results in this:

DATEADD(dd, -1, @year + '-' + MONTH(b.shpdate) + '-01')

Can you post the code for populating the variable @year?


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1321730
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse