Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Having problem that my Sql Query is "
SQL
SELECT a.in_ts,a.jobCode,b.name 'CompanyName',a.jobName,a.contactPerson,a.cpDesignation,a.location,a.jobType,a.monthlySalary,a.qualification,a.experience,a.remarks FROM tg_jobMaster a, tg_companyMaster b WHERE a.companyCode=b.companyCode AND convert(varchar(10),a.in_ts,101) BETWEEN '12/30/2012' AND '03/07/2013' AND isAllocated is NULL AND isExpired is NULL ORDER BY a.jobCode DESC

".This query is not working but When i am selecting fromdate 02/30/2012 this query is working.
Plz solve the problem.
Posted
Comments
Shanalal Kasim 7-Mar-13 0:33am    
Please provide table structure with sample data
__TR__ 7-Mar-13 0:49am    
What do you mean by "The query is not working". Are you getting any error message or its just the query is not returning any rows?

Edit: If you are getting an error its because 02/30/2012 is february 30th which is an invalid date.
Davidduraisamy 7-Mar-13 1:14am    
have you got the result?

Try this one:
SQL
SELECT a.in_ts,
       a.jobCode,
       b.name 'CompanyName',
       a.jobName,
       a.contactPerson,
       a.cpDesignation,
       a.location,
       a.jobType,
       a.monthlySalary,
       a.qualification,
       a.experience,
       a.remarks
FROM   tg_jobMaster         a,
       tg_companyMaster     b
WHERE  a.companyCode = b.companyCode
       AND CONVERT(DATETIME,a.in_ts, 101) BETWEEN CONVERT(DATETIME,'12/30/2012',101) AND CONVERT(DATETIME,'03/07/2013',101)
       AND isAllocated IS NULL
       AND isExpired IS NULL
ORDER BY
       a.jobCode DESC
 
Share this answer
 
try the below approach

SQL
DECLARE @FromDate DATETIME
DECLARE @ToDate DATETIME

SET @FromDate = '12/30/2012'
SET @ToDate = '03/07/2013'

SELECT a.in_ts,
a.jobCode,
b.name 'CompanyName',
a.jobName,
a.contactPerson,
a.cpDesignation,
a.location,
a.jobType,
a.monthlySalary,
a.qualification,
a.experience,
a.remarks 
FROM tg_jobMaster a, tg_companyMaster b 
WHERE a.companyCode=b.companyCode 
AND DATEDIFF(DAY,a.in_ts,@Todate) >= 0 AND DATEDIFF(DAY,a.in_ts,@FromDate) <= 0
AND isAllocated is NULL 
AND isExpired is NULL 
ORDER BY a.jobCode DESC
 
Share this answer
 
v2
Use this condition:

convert(varchar(10),ExpDate,112) between convert(varchar(10),'20121230' ,112) and convert(varchar(10),'20130123' ,112)
 
Share this answer
 

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