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
 Date conversion error

Author  Topic 

soniyakapoor03
Starting Member

11 Posts

Posted - 2006-03-04 : 01:47:54
hi guys,

i am passing date value from a textbox in c# and asp.net.
i am calling an sql procedure .
The result is binding to a datagrid.
my sql procedure is like this


create procedure searchComplaintdetails
(
@FirstName nvarchar(50),
@DueDate DateTime

)
as
DECLARE @SQL varchar(5000)
SET @SQL = 'select Customers.CustomerFirstName as Name,ComplaintLog.LogDate,ComplaintLog.LogID,
ComplaintLog.ComplaintStatus,ComplaintLog.DueDate,ComplaintCategories.CategoryName from ComplaintLog
Join ComplaintCategories on ComplaintLog.CategoryID=ComplaintCategories.CategoryID
join Customers on ComplaintLog.CustomerID=Customers.CustomerID
where ComplaintLog.IsActive=1'


IF Datalength(@FirstName)>0
SET @SQL = @SQL + ' AND Customers.CustomerFirstName LIKE ''' + @FirstName + '%'''

IF Datalength(@DueDate)>0
SET @SQL = @SQL + ' AND Convert(DateTime(10),ComplaintLog.DueDate,101) = '+@DueDate + ' '


EXEC (@SQL)
GO

my error is Syntax error converting datetime from character string.

if i pass nothing in test boxit will show another error

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

Kristen
Test

22859 Posts

Posted - 2006-03-04 : 02:32:00
You don't really want, or need, to be doing this in dynamic SQL in the Sproc.

create procedure dbo.searchComplaintdetails
(
@FirstName nvarchar(50),
@DueDate DateTime
)
as
select Customers.CustomerFirstName as Name,
ComplaintLog.LogDate,
ComplaintLog.LogID,
ComplaintLog.ComplaintStatus,
ComplaintLog.DueDate,
ComplaintCategories.CategoryName
from dbo.ComplaintLog
Join dbo.ComplaintCategories
on ComplaintLog.CategoryID=ComplaintCategories.CategoryID
join dbo.Customers
on ComplaintLog.CustomerID=Customers.CustomerID
where ComplaintLog.IsActive=1
AND (
NullIf(@FirstName, '') IS NULL
OR Customers.CustomerFirstName LIKE @FirstName + '%'
)
AND (
@DueDate IS NULL
OR (
@DueDate < ComplaintLog.DueDate
AND ComplaintLog.DueDate < DATEADD(Day, 1, @DueDate)
)
)


Kristen
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-03-04 : 02:35:16
what format you are passing datatime from your front end?

why you are converting?
does this doesnt work for you??
ComplaintLog.DueDate = '+@DueDate + ' '

Can you post some sample data ??


Sucess Comes to those who Believe in Beauty of their Dream..
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-03-04 : 02:47:00
"why you are converting?"

I presumed because ComplaintLog.DueDate holds time, as well as date.

Kristen
Go to Top of Page

soniyakapoor03
Starting Member

11 Posts

Posted - 2006-03-04 : 04:55:47
quote:
Originally posted by Kristen

"why you are converting?"

I presumed because ComplaintLog.DueDate holds time, as well as date.

Kristen



thanks for your help.
It's working Now.
Go to Top of Page
   

- Advertisement -