Destiny Amana
asked on
Upsizing from Access to MSSQL, Problem with SQL code and Functions not found in SQL
this statement works well in ACCESS
TbillSQL = "SELECT tbl_research_tbills.autoid , CDate(Format(tbl_research_ tbills.tbi lldate,'dd /mm/yy')) AS NEWDATE, tbl_research_tbills.mrr, tbl_research_tbills.subscr iption, "&_
"tbl_research_tbills.amoun tonoffer, tbl_research_tbills.allotm ent, tbl_research_tbills.stopra te, tbl_research_tbills.trueyi eld "&_
"FROM tbl_research_tbills "&_
"WHERE CDate(Format(tbl_research_ tbills.tbi lldate,'dd /mm/yy')) Between #"& startdate &"# And #"& enddate &"# "&_
"ORDER BY CDate(Format(tbl_research_ tbills.tbi lldate,'dd /mm/yy'))"
But once I change the databse to MSSQL, I get this error message
[Microsoft][ODBC SQL Server Driver][SQL Server]'Format' is not a recognized function name.
HELP!!!
TbillSQL = "SELECT tbl_research_tbills.autoid
"tbl_research_tbills.amoun
"FROM tbl_research_tbills "&_
"WHERE CDate(Format(tbl_research_
"ORDER BY CDate(Format(tbl_research_
But once I change the databse to MSSQL, I get this error message
[Microsoft][ODBC SQL Server Driver][SQL Server]'Format' is not a recognized function name.
HELP!!!
ASKER
The Date is in the format 04-Jan-96 will this be recognised by MSSQL as a Date?
yes, and why is the date in a TEXT field? If that is the format of the DateTime field, then no big deal. The Date format as set in the table is PURELY for display purposes only. DateTime values are actually held in the tables without ANY formatting whatsoever. In fact, Access TDateTime values are stored as Numbers with a decimal point.
The value of the number to the LEFT of the decimal point is the count of the number of days since the base date of 30 DEC 1899. The value of the number to the RIGHT of the decimal point is the time, measured in seconds since Midnight, as a fraction of 1 day (1 day = 86400 seconds) so that Noon would have the fractional value of 0.5. The Format property of a DateTime field simply controls how the Date and Time are displyed, and has nothing at all to do with out the value is actually held in the table. As I said, all of your cDate and Format gyrations were a pure waste of time and totally un-necessary.. SQL Server will be able to handle your DateTime fields just fine.
AW
The value of the number to the LEFT of the decimal point is the count of the number of days since the base date of 30 DEC 1899. The value of the number to the RIGHT of the decimal point is the time, measured in seconds since Midnight, as a fraction of 1 day (1 day = 86400 seconds) so that Noon would have the fractional value of 0.5. The Format property of a DateTime field simply controls how the Date and Time are displyed, and has nothing at all to do with out the value is actually held in the table. As I said, all of your cDate and Format gyrations were a pure waste of time and totally un-necessary.. SQL Server will be able to handle your DateTime fields just fine.
AW
ASKER
yes, ! GREAT!
and why is the date in a TEXT field
-- data is uploaded via a text file which is read into the database from excel.
Thanks.
i will take out the extra superfluous code and test then return to give you full credit!
and why is the date in a TEXT field
-- data is uploaded via a text file which is read into the database from excel.
Thanks.
i will take out the extra superfluous code and test then return to give you full credit!
ASKER
well, the pages are now displaying but the query is not doing a date filter that works.
The dates are not being recognised correctly.
What next?
The dates are not being recognised correctly.
What next?
there is no format function in SQL server,
you can use CONVERT for this, please refer BOL for convert
you can use CONVERT for this, please refer BOL for convert
ASKER
I do not understand.
How do I apply the convert function to work the same way the original SQL statement worked with Access whenthe date format is 01-apr-05
Thanks
How do I apply the convert function to work the same way the original SQL statement worked with Access whenthe date format is 01-apr-05
Thanks
declare @TbillSQL varchar(1000),@startdate varchar(10), @enddate varchar(10)
SET @startdate = '2/12/06'
set @enddate = '10/12/06'
SET @TbillSQL = 'SELECT tbl_research_tbills.autoid ,
CONVERT(varchar(8),tbl_res earch_tbil ls.tbillda te,3) AS NEWDATE,
tbl_research_tbills.mrr, tbl_research_tbills.subscr iption, '+
'tbl_research_tbills.amoun tonoffer, tbl_research_tbills.allotm ent, tbl_research_tbills.stopra te, tbl_research_tbills.trueyi eld '+
'FROM tbl_research_tbills '+
'WHERE CONVERT(varchar(8),tbl_res earch_tbil ls.tbillda te,3) Between '''+@startdate +
''' And '''+@enddate +''' ORDER BY tbl_research_tbills.tbilld ate '
print @TbillSQL
SET @startdate = '2/12/06'
set @enddate = '10/12/06'
SET @TbillSQL = 'SELECT tbl_research_tbills.autoid
CONVERT(varchar(8),tbl_res
tbl_research_tbills.mrr, tbl_research_tbills.subscr
'tbl_research_tbills.amoun
'FROM tbl_research_tbills '+
'WHERE CONVERT(varchar(8),tbl_res
''' And '''+@enddate +''' ORDER BY tbl_research_tbills.tbilld
print @TbillSQL
in order to execute the above code
simply use
exec (@TbillSQL)
simply use
exec (@TbillSQL)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
tbl_research_tbills
is already a DateTime field to begin with. YOu can simply compare one datetime field to another, or to a range of date value, using Between. There is no need to Format the DateTime fioeld, and then use the cDate function to convert it back into a DateTime value. The does absolutely nothing.
AW