Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi

query like:
SQL
where CONVERT(VARCHAR(10),CreatedDateTime,111) LIKE ''' +2012-07-25 + '%''

Please check my where condition, did I place the single quotes correctly where 2012-07-25 it is in nvarchar type.Where CreatedDateTime is like 2012-07-25 13:51:59.537.

I am getting an error is:
The data types varchar and varchar are incompatible in the modulo operator.

Why I written like this I want to check on a particular date from user on CreatedDateTime contains 2012-07-25.
I think is little bit confusing to you but try to understand my problem and please place the single quotes in correct.

Thanking you.
Posted
Updated 8-Aug-12 20:33pm
v3

SQL
where CONVERT(VARCHAR(10),CreatedDateTime,101) LIKE '07/25/2012%'



Thanks
Ashish
 
Share this answer
 
Comments
Madhugundi 9-Aug-12 3:02am    
i tried like ur post but i am getting Zero count for every hour
AshishChaudha 9-Aug-12 3:49am    
Try this once..I had tried using my tables..working fine

SELECT DATEPART(HOUR, convert(Datetime,CreatedDateTime,13)) AS [Hour of Day] , Id AS [TotalShipOrders] FROM ShipmentDetail where CONVERT(VARCHAR,CreatedDateTime,101) LIKE '07/25/2012%' Union ALL SELECT Hour, NULL From @Hours
try this

SQL
where CONVERT(VARCHAR(10),validfromdate,111) LIKE '2012/07/25%'
 
Share this answer
 
Comments
Madhugundi 9-Aug-12 3:02am    
i tried like ur post but i am getting Zero count for every hour
Santhosh Kumar Jayaraman 9-Aug-12 3:03am    
for every hour? i didnt understand that, can you explain me?You are searching with hour also?
Madhugundi 9-Aug-12 3:13am    
Declare @Hours Table (Hour int);
Declare @i as int;
Set @i = 5
While @i < 24
Begin
Insert into @Hours
Values(@i);

Set @i = @i + 1;
End;

Select
[Hour of Day],
Count([TotalShipOrders]) as Total
From
(
SELECT
DATEPART(HOUR, convert(Datetime,CreatedDateTime,13)) AS [Hour of Day]
, Id AS [TotalShipOrders]
FROM ShipmentDetail where CONVERT(VARCHAR(10),CreatedDateTime,111) LIKE +2012-07-25 + '%'
Union ALL
SELECT Hour, NULL
From @Hours
) as Data

GROUP BY [Hour of Day]
ORDER BY [Hour of Day]

i want the where condition is like
where CONVERT(VARCHAR(10),CreatedDateTime,111) LIKE '2012-07-25 %'

2012-07-25 it is passed by user from Application.
CreatedDateTime is like 2012-07-25 15:54:32.843

Plese help how to place single quotes.
Madhugundi 9-Aug-12 3:14am    
Based on 2012-07-25 this date i want get records from CreatedDateTime is like 2012-07-25 15:54:32.843 i am grouping by hour
Santhosh Kumar Jayaraman 9-Aug-12 3:15am    
you have to use '/' in date instead of 2012-07-05.. It should be 2012/07/05.. Use replace function to replace - with /

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900