| Author |
Topic |
|
ConfusedAgain
Yak Posting Veteran
82 Posts |
Posted - 2010-09-21 : 12:22:09
|
| I have a transaction table and I have a account table. In the account table I have a StartDate and EndDate both are DataTypes nVarChar(50)In the transaction table I have bookings with a EnterDate (nVarChar(50))I need to identify which records in the Trans table fall within the Start and End Date of the account table.This I need to show in a SQL View. Thanks |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-21 : 12:26:39
|
| how are you storing the dates i.e in what format?By using nvarchar fields you're only making the date manipulations really hard for yourself. Always try to use proper datatypes for your fields.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
ConfusedAgain
Yak Posting Veteran
82 Posts |
Posted - 2010-09-21 : 12:31:59
|
| I agree it would be better stored as DateTime fields but the principle of the SQL would still be the same.I can get this to work if I link MS Access to the tables and write the query there but if I transfer this to SQL Server the SQL does not work.This is the SQL in MS AccessSELECT IIf(Transactions.ConnectTime<Conf_Dates.StartDate,'Yes','No') AS StartOKFROM Transactions LEFT JOIN Conf_Dates ON CDR_Transactions.ConfRefNum = Conf_Dates.ConfRefNum; |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-21 : 12:36:25
|
quote: Originally posted by ConfusedAgain I agree it would be better stored as DateTime fields but the principle of the SQL would still be the same.I can get this to work if I link MS Access to the tables and write the query there but if I transfer this to SQL Server the SQL does not work.This is the SQL in MS AccessSELECT IIf(Transactions.ConnectTime<Conf_Dates.StartDate,'Yes','No') AS StartOKFROM Transactions LEFT JOIN Conf_Dates ON CDR_Transactions.ConfRefNum = Conf_Dates.ConfRefNum;
not alwaysstoring it as varchar will cause problems when you're trying to do comparisons among values which is exactly what you want in this case.so in your case you've actually convert them back to dates before you can compare. for that you need to determine what all formats they're storing dates currently------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
ConfusedAgain
Yak Posting Veteran
82 Posts |
Posted - 2010-09-21 : 12:54:28
|
| Ok if I can convert them to DateTime datatype how would display which records fall between these dates. |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-09-21 : 13:33:49
|
| Use the CASE statementSELECT CASE WHEN Transactions.ConnectTime < Conf_Dates.StartDate THEN 'Yes' ELSE 'No' END as StartOkJimEveryday I learn something that somebody else already knew |
 |
|
|
ConfusedAgain
Yak Posting Veteran
82 Posts |
Posted - 2010-09-21 : 13:47:14
|
| Thank you kindly Jim, that works a treat. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
ConfusedAgain
Yak Posting Veteran
82 Posts |
Posted - 2010-09-21 : 14:23:23
|
| They do have to be between to date times but I can add another expression that show if it is before the end time. I will try to convert these to DateTime Fields if I do this will the same query work do you know? |
 |
|
|
|