patternsqlMinor
How could i search between two string type date
Viewed 0 times
searchcoulddatetypetwobetweenhowstring
Problem
Consider these two tables. I use persian dates, so I have to declare
crt table:
season table:
I want to write a query that gives me crt records that are valid in a season. IE
How do I do that?
startdate and enddate as a string(nvarchar(10)).crt table:
id title startdate enddate
--------------------------
1 xyz 1395/01/01 1395/12/29
2 xyy 1394/12/01 1395/05/05
3 cvb 1392/02/03 1394/02/03season table:
id title startdate enddate
--------------------------
1 spring95 1395/01/01 1395/03/31I want to write a query that gives me crt records that are valid in a season. IE
crt.startdate=season.enddate.How do I do that?
Solution
If you encounter performance problems you could store the dates as integers instead of varchar. 1397-12-09 becomes 13971209, all the numbers remain in sequence so you can still carry out BETWEEN queries. Then convert your results to date format at the final point of presentation.
Context
StackExchange Database Administrators Q#156620, answer score: 3
Revisions (0)
No revisions yet.