| Author |
Topic |
|
ganny
Yak Posting Veteran
51 Posts |
Posted - 2009-01-07 : 05:46:29
|
| Hi I am getting the below mentioned error while executing my StoredProcedure since i have written my query as=============convert(varchar(20),datediff(minute,depdate,confirmdate)/(24*60))+':'+convert(varchar(20),datediff(minute,depdate,confirmdate)%(24*60)/60) as Ageing=============ERROR MSG:"Conversion failed when converting the varchar value '0:3' to data type int"Kindly assist me someone. |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-01-07 : 05:55:05
|
| Can you post the full query ? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-07 : 05:57:53
|
| select convert(varchar(20),convert(varchar(20),datediff(minute,depdate,confirmdate))/(24*60))+':'+convert(varchar(20),convert(varchar(20),datediff(minute,depdate,confirmdate))/)%(24*60)/60) )as Ageing |
 |
|
|
ganny
Yak Posting Veteran
51 Posts |
Posted - 2009-01-07 : 06:31:56
|
quote: Originally posted by sakets_2000 Can you post the full query ?
SELECT booking.agencyid,allschedules.Vessel, allschedules.Voyage, allschedules.Bound, allschedules.port, allschedules.arrdate, allschedules.depdate, booking.datecr,booking.confirmdate,case when (datediff(hh,allschedules.depdate,booking.confirmdate)<= 24) then booking.book_no else 'N' end Draft_At_Dep, case when (datediff(hh,allschedules.depdate,booking.confirmdate) > 24) then booking.book_no else 'N' end bkg24hrsDraftbkg, case when (booking.datecr > allschedules.depdate) then booking.book_no else 'N' end aftervsldep, booking.status into #tempsemiFROM allschedules INNER JOIN booking ON allschedules.port= booking.loadportid and allschedules.terminal = booking.polterminal and allschedules.vessel=booking.vesselcode and allschedules.voyage=booking.voyagecode and allschedules.Bound=booking.bound WHERE allschedules.depdate >= @FromDate + '00:00' and allschedules.depdate <= @ToDate + '23:59' and allschedules.port in (select string from #tmpport) and booking.status in ('C')full query here:select agencyid,vessel,voyage,Bound,Port,arrdate,depdate,datecr,Draft_At_dep as Draft_ATDep,bkg24hrsDraftbkg as Draft_24hrsDep, aftervsldep,confirmdate,status, convert(varchar(20),convert(varchar(20),datediff(minute,depdate,confirmdate))/(24*60))+':'+convert(varchar(20),convert(varchar(20),datediff(minute,depdate,confirmdate))%(24*60)/60) as Ageing into #tempfinal1from #tempsemi order by depdate,arrdateselect * from #tempfinal1 |
 |
|
|
ganny
Yak Posting Veteran
51 Posts |
Posted - 2009-01-07 : 06:33:20
|
quote: Originally posted by bklr select convert(varchar(20),convert(varchar(20),datediff(minute,depdate,confirmdate))/(24*60))+':'+convert(varchar(20),convert(varchar(20),datediff(minute,depdate,confirmdate))/)%(24*60)/60) )as Ageing
dear bklr, its not working, still its showing the same error as "Conversion failed when converting the varchar value '0:13' to data type int."Please assist. |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-07 : 06:49:32
|
| the query is working check this once select convert(varchar(20),datediff(minute,'2008-12-10 15:21:15.580',getdate())/(24*60))+':'+convert(varchar(20),datediff(minute,'2008-12-10 15:21:15.580',getdate())%(24*60)/60)see difference for this and that queryselect datediff(minute,'2008-12-10 15:21:15.580',getdate())/(24*60)+':'+datediff(minute,'2008-12-10 15:21:15.580',getdate())%(24*60)/60 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-07 : 06:57:55
|
Simpler...SELECT CAST(DATEDIFF(SECOND, DepDate, ConfirmDate) / 86400 AS VARCHAR(12)) + ':' + CAST(DATEDIFF(SECOND, DepDate, ConfirmDate) / 3600 AS VARCHAR(12))FROM #tempSemi E 12°55'05.63"N 56°04'39.26" |
 |
|
|
ganny
Yak Posting Veteran
51 Posts |
Posted - 2009-01-07 : 07:10:32
|
quote: Originally posted by Peso Simpler...SELECT CAST(DATEDIFF(SECOND, DepDate, ConfirmDate) / 86400 AS VARCHAR(12)) + ':' + CAST(DATEDIFF(SECOND, DepDate, ConfirmDate) / 3600 AS VARCHAR(12))FROM #tempSemi E 12°55'05.63"N 56°04'39.26"
No,, its not working Peso and bklr.if i execute the same query seperately as you given, its working. where the same is not working in my stored procedure.please help someone.. |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-01-07 : 07:23:07
|
| Are you doing an insert into #tempfinal1 ? The column corresponding to Ageing in your query must be declared an int on the temp table. You might want to change it to varchar. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-07 : 09:53:41
|
quote: Originally posted by ganny
quote: Originally posted by Peso Simpler...SELECT CAST(DATEDIFF(SECOND, DepDate, ConfirmDate) / 86400 AS VARCHAR(12)) + ':' + CAST(DATEDIFF(SECOND, DepDate, ConfirmDate) / 3600 AS VARCHAR(12))FROM #tempSemi E 12°55'05.63"N 56°04'39.26"
No,, its not working Peso and bklr.if i execute the same query seperately as you given, its working. where the same is not working in my stored procedure.please help someone..
then post your full procedure code. |
 |
|
|
ganny
Yak Posting Veteran
51 Posts |
Posted - 2009-01-08 : 01:14:31
|
| here is my full query, pls assist..CREATE PROCEDURE Lsp_DrBook @FromDate datetime, @ToDate datetime, @Port varchar(max) As BEGIN declare @FinalBooking table (Agency varchar(20),VesselCode varchar(20),VoyageCode varchar(20),Bound char(1), Port varchar(100), VesselArrive datetime, VesselDepature datetime, BokkingCrtd datetime, ConfirmDate datetime,DraftBkg_AtDepature varchar(30),DraftBkg_Depature_24hr varchar(30), BkgCrtd_AfterDepature varchar(30), BkgStatus varchar(20), BkgCreated varchar(20)) select * into #tmpport from OperationactivityinsertTemp(@Port) insert into @FinalBooking (Agency,VesselCode,VoyageCode,Bound,Port,VesselArrive,VesselDepature,BokkingCrtd,ConfirmDate,DraftBkg_AtDepature,DraftBkg_Depature_24hr, BkgCrtd_AfterDepature, BkgStatus) SELECT booking.agencyid,allschedules.Vessel, allschedules.Voyage, allschedules.Bound, allschedules.port, allschedules.arrdate, allschedules.depdate, booking.datecr,booking.confirmdate, booking.book_no,case when (DATEADD(hh, 24, allschedules.depdate )<= (getdate())) then booking.book_no else 'N' end bkg24hrsDraftbkg, case when (booking.datecr > allschedules.depdate) then booking.book_no else 'N' end aftervsldep, booking.status FROM allschedules INNER JOIN booking ON allschedules.port= booking.loadportid and allschedules.terminal = booking.polterminal and allschedules.vessel=booking.vesselcode and allschedules.voyage=booking.voyagecode and allschedules.Bound=booking.bound WHERE allschedules.depdate >= @FromDate + '00:00' and allschedules.depdate <= @ToDate + '23:59' and allschedules.port in (select string from #tmpport) and booking.status in ('D') select Agency,VesselCode,VoyageCode,Bound,Port,VesselArrive,VesselDepature,BokkingCrtd,(case when (DraftBkg_Depature_24hr='N' and BkgCrtd_AfterDepature='N') then DraftBkg_AtDepature else 'N' end ) Draft_ATDep, (case when BkgCrtd_AfterDepature='N' then DraftBkg_Depature_24hr else 'N' end) Draft_24hrsDep, BkgCrtd_AfterDepature,ConfirmDate,BkgStatus,datediff(hh,VesselDepature,ConfirmDate) as Ageing into #tempfinalfrom @FinalBooking order by VesselArrive,VesselDepature SELECT booking.agencyid,allschedules.Vessel, allschedules.Voyage, allschedules.Bound, allschedules.port, allschedules.arrdate, allschedules.depdate, booking.datecr,booking.confirmdate,case when (datediff(hh,allschedules.depdate,booking.confirmdate)<= 24) then booking.book_no else 'N' end Draft_At_Dep, case when (datediff(hh,allschedules.depdate,booking.confirmdate) > 24) then booking.book_no else 'N' end bkg24hrsDraftbkg, case when (booking.datecr > allschedules.depdate) then booking.book_no else 'N' end aftervsldep, booking.status into #tempsemiFROM allschedules INNER JOIN booking ON allschedules.port= booking.loadportid and allschedules.terminal = booking.polterminal and allschedules.vessel=booking.vesselcode and allschedules.voyage=booking.voyagecode and allschedules.Bound=booking.bound WHERE allschedules.depdate >= @FromDate + '00:00' and allschedules.depdate <= @ToDate + '23:59' and allschedules.port in (select string from #tmpport) and booking.status in ('C')select agencyid,vessel,voyage,Bound,Port,arrdate,depdate,datecr,Draft_At_dep as Draft_ATDep,bkg24hrsDraftbkg as Draft_24hrsDep, aftervsldep,confirmdate,status,convert(varchar(20),datediff(minute,depdate,confirmdate)/(24*60)) +':'+convert(varchar(20),datediff(minute,depdate,confirmdate)%(24*60)/60) as Ageing into #tempfinal1from #tempsemi order by depdate,arrdatedelete from #tempfinal1 where confirmdate < depdate select agency,vesselcode,voyagecode,bound,port,vesselarrive,vesseldepature,bokkingcrtd,draft_atdep,draft_24hrsdep,bkgcrtd_afterdepature,confirmdate,bkgstatus,ageing from #tempfinalunionselect agencyid,vessel,voyage,bound,port,arrdate,depdate,datecr,draft_atdep,draft_24hrsdep,aftervsldep,confirmdate,status,ageing from #tempfinal1drop table #tempfinaldrop table #tempsemidrop table #tempfinal1END |
 |
|
|
ganny
Yak Posting Veteran
51 Posts |
Posted - 2009-01-08 : 02:04:54
|
| is anyone can help? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-08 : 02:43:43
|
I know the error.For #tempFinal, you have INT as datatype for Ageing -> DATEDIFF(HOUR, ... )For #tempFinal1, you have VARCHAR as datatype for AgeingAnd since you have SELECTed from #tempFinal first in the final UNION, the datatype for complete resultset is INT.This is 101.Use this codeCREATE PROCEDURE Lsp_DrBook( @FromDate DATETIME, @ToDate DATETIME, @Port VARCHAR(MAX))ASSET NOCOUNT ONDECLARE @FinalBooking TABLE ( Agency VARCHAR(20), VesselCode VARCHAR(20), VoyageCode VARCHAR(20), Bound CHAR(1), Port VARCHAR(100), VesselArrive DATETIME, VesselDepature DATETIME, BokkingCrtd DATETIME, ConfirmDate DATETIME, DraftBkg_AtDepature VARCHAR(30), DraftBkg_Depature_24hr VARCHAR(30), BkgCrtd_AfterDepature VARCHAR(30), BkgStatus VARCHAR(20), BkgCreated VARCHAR(20) ) SELECT *INTO #tmpPortFROM OperationactivityinsertTemp(@Port)INSERT @FinalBooking ( Agency, VesselCode, VoyageCode, Bound,Port, VesselArrive, VesselDepature, BokkingCrtd, ConfirmDate, DraftBkg_AtDepature, DraftBkg_Depature_24hr, BkgCrtd_AfterDepature, BkgStatus ) SELECT b.agencyid, als.Vessel, als.Voyage, als.Bound, als.port, als.arrdate, als.depdate, b.datecr, b.confirmdate, b.book_no, CASE WHEN DATEADD(hh, 24, als.depdate) <= GETDATE() THEN b.book_no ELSE 'N' END AS bkg24hrsDraftbkg, CASE WHEN b.datecr > als.depdate THEN b.book_no ELSE 'N' END AS aftervsldep, b.status FROM allschedules AS alsINNER JOIN booking AS b ON b.loadportid = als.port and als.terminal = b.polterminal and als.vessel = b.vesselcode and als.voyage = b.voyagecode and als.Bound = b.bound INNER JOIN #tmpPort AS p ON p.string = als.portWHERE als.depdate >= @FromDate and als.depdate < @ToDate + 1 and b.status = 'D'SELECT Agency, VesselCode, VoyageCode, Bound,Port, VesselArrive, VesselDepature, BokkingCrtd, CASE WHEN DraftBkg_Depature_24hr = 'N' AND BkgCrtd_AfterDepature = 'N' THEN DraftBkg_AtDepature ELSE 'N' END AS Draft_ATDep, CASE WHEN BkgCrtd_AfterDepature = 'N' THEN DraftBkg_Depature_24hr ELSE 'N' END AS Draft_24hrsDep, BkgCrtd_AfterDepature, ConfirmDate, BkgStatus, CAST(DATEDIFF(HOUR, VesselDepature, ConfirmDate) AS VARCHAR(12)) AS AgeingINTO #tempFinalFROM @FinalBookingSELECT b.agencyid, als.Vessel, als.Voyage, als.Bound, als.port, als.arrdate, als.depdate, b.datecr, b.confirmdate, CASE WHEN DATEDIFF(HOUR, als.depdate, b.confirmdate) <= 24 THEN b.book_no ELSE 'N' END AS Draft_At_Dep, CASE WHEN DATEDIFF(HOUR, als.depdate, b.confirmdate) > 24 THEN b.book_no ELSE 'N' END AS bkg24hrsDraftbkg, CASE WHEN b.datecr > als.depdate THEN b.book_no ELSE 'N' END AS aftervsldep, b.statusINTO #tempSemiFROM allschedules AS alsINNER JOIN booking AS b ON als.port = b.loadportid AND als.terminal = b.polterminal AND als.vessel = b.vesselcode AND als.voyage = b.voyagecode AND als.Bound = b.bound INNER JOIN #tmpPort AS p ON p.string = als.portWHERE als.depdate >= @FromDate AND als.depdate < @ToDate + 1 AND b.status = 'C'SELECT agencyid, vessel, voyage, Bound, Port, arrdate, depdate, datecr, Draft_At_dep as Draft_ATDep, bkg24hrsDraftbkg as Draft_24hrsDep, aftervsldep, confirmdate, status, CAST(DATEDIFF(SECOND, DepDate, ConfirmDate) / 86400 AS VARCHAR(12)) + ':' + CAST(DATEDIFF(SECOND, DepDate, ConfirmDate) / 3600 AS VARCHAR(12)) AS AgeingINTO #tempFinal1FROM #tempSemiWHERE confirmDate >= depDate SELECT agency, vesselcode, voyagecode, bound, port, vesselarrive, vesseldepature, bokkingcrtd, draft_atdep, draft_24hrsdep, bkgcrtd_afterdepature, confirmdate, bkgstatus, ageingFROM #tempFinalUNIONSELECT agencyid, vessel, voyage, bound, port, arrdate, depdate, datecr, draft_atdep, draft_24hrsdep, aftervsldep, confirmdate, status, ageingFROM #tempFinal1ORDER BY VesselArrive, VesselDepature DROP TABLE #tempFinal, #tempSemi, #tempFinal1 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
ganny
Yak Posting Veteran
51 Posts |
Posted - 2009-01-08 : 02:51:45
|
| Dear Peso, i understood my mistakes in the SP.Thank you so much for your valuable reply to me. |
 |
|
|
|
|
|