here is mah query..
USE [BMS]
GO
/****** Object: StoredProcedure [dbo].[sp_SearchParticularsDetailsByPivot] Script Date: 18-07-2016 14:15:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[sp_SearchParticularsDetailsByPivot]
(
@fromdate datetime,
@todate datetime
)
as
begin
declare @expenseNames nvarchar(max)='';
--select @expenseNames ='[Building_EXPENSES], [eLECTRIC]'
--select @expenseNames= case when datalength(@expenseNames) = 0 then '' else ', ' end + '[' + ltrim(rtrim(Expenses_Name)) + ']'
--from expenses
(select @expenseNames +=
+'['+Expenses_Name+']'
+','
FROM dbo.Expenses)
set @expenseNames=(SELECT LEFT(@expenseNames, (LEN(@expenseNames)-1)))
declare @dynamicSQL nvarchar(max)='';
select @dynamicSQL =
'select * from
(select dbo.CreditDebit.ID AS SLNO, TransactionDate, Particular,Expenses_Name,Debit_Expenses,Credit_Expenses,Expenses,
Balance from dbo.CreditDebit inner join
dbo.CreditExpenses on dbo.CreditDebit.ID=dbo.CreditExpenses.Credit_ID
inner join dbo.Expenses on dbo.CreditExpenses.Expenses_ID=dbo.Expenses.ID
where dbo.CreditDebit.TransactionDate between cast("'+@fromdate+'",datetime) and cast("'+@todate+'",datetime) )src
pivot
(
sum(Expenses)
for Expenses_Name In ('+@expenseNames+')
)as pvt'
EXEC (@dynamicSQL)
end
when i execute this query i got error as
Msg 241, Level 16, State 1, Procedure sp_SearchParticularsDetailsByPivot, Line 20
Conversion failed when converting date and/or time from character string.
19 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
ketan borsdiyaPosted Jul 19, 2016, 3:28 AM
sourabh choubeyPosted Jul 19, 2016, 3:20 AM
ketan borsdiyaPosted Jul 19, 2016, 3:08 AM
sourabh choubeyPosted Jul 19, 2016, 3:00 AM
ketan borsdiyaPosted Jul 19, 2016, 2:56 AM
sourabh choubeyPosted Jul 19, 2016, 2:18 AM
sourabh choubeyPosted Jul 19, 2016, 1:48 AM
sourabh choubeyPosted Jul 19, 2016, 1:42 AM
ketan borsdiyaPosted Jul 19, 2016, 1:28 AM
sourabh choubeyPosted Jul 18, 2016, 3:05 PM
sourabh choubeyPosted Jul 18, 2016, 11:04 AM
sourabh choubeyPosted Jul 18, 2016, 11:03 AM
ketan borsdiyaPosted Jul 18, 2016, 9:27 AM
sourabh choubeyPosted Jul 18, 2016, 9:18 AM
ketan borsdiyaPosted Jul 18, 2016, 7:56 AM
Vishal JadavPosted Jul 18, 2016, 7:32 AM
sourabh choubeyPosted Jul 18, 2016, 7:05 AM
ketan borsdiyaPosted Jul 18, 2016, 6:32 AM
Vishal JadavPosted Jul 18, 2016, 6:01 AM