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.tbilldate,'dd/mm/yy')) AS NEWDATE, tbl_research_tbills.mrr, tbl_research_tbills.subscription, "&_
                                                      "tbl_research_tbills.amountonoffer, tbl_research_tbills.allotment, tbl_research_tbills.stoprate, tbl_research_tbills.trueyield "&_
                                                      "FROM tbl_research_tbills "&_
                                                      "WHERE CDate(Format(tbl_research_tbills.tbilldate,'dd/mm/yy')) Between #"& startdate &"# And #"& enddate  &"# "&_
                                                      "ORDER BY CDate(Format(tbl_research_tbills.tbilldate,'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!!!
LVL 1
souldjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Arthur_WoodCommented:
why are you going through these wild formatting and then conversion to a Data value, when it appears the the field in

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
0
souldjAuthor Commented:
The Date is in the format 04-Jan-96 will this be recognised by MSSQL as a Date?
0
Arthur_WoodCommented:
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

souldjAuthor Commented:
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!
0
souldjAuthor Commented:
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?
0
Aneesh RetnakaranDatabase AdministratorCommented:
there is no format function in SQL server,
you can use CONVERT for this, please refer BOL for convert
0
souldjAuthor Commented:
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
0
Aneesh RetnakaranDatabase AdministratorCommented:
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_research_tbills.tbilldate,3) AS NEWDATE,
             tbl_research_tbills.mrr, tbl_research_tbills.subscription, '+
             'tbl_research_tbills.amountonoffer, tbl_research_tbills.allotment, tbl_research_tbills.stoprate, tbl_research_tbills.trueyield '+
             'FROM tbl_research_tbills '+
             'WHERE CONVERT(varchar(8),tbl_research_tbills.tbilldate,3) Between '''+@startdate  +
             ''' And '''+@enddate  +''' ORDER BY tbl_research_tbills.tbilldate '
print @TbillSQL
0
Aneesh RetnakaranDatabase AdministratorCommented:
in order to execute the above code
simply use

exec (@TbillSQL)
0
junglerover77Commented:
According to your syntax, I think you are using VB or VB.NET. So just try the following statement:

  TbillSQL = "SELECT tbl_research_tbills.autoid, CDate(Format(tbl_research_tbills.tbilldate,'dd/mm/yy')) AS NEWDATE, tbl_research_tbills.mrr, tbl_research_tbills.subscription, " & _
            "tbl_research_tbills.amountonoffer, tbl_research_tbills.allotment, tbl_research_tbills.stoprate, tbl_research_tbills.trueyield " & _
            "FROM tbl_research_tbills " & _
            "WHERE CDate(tbl_research_tbills.tbilldate) Between CDate('" & startdate & "') And CDate('" & enddate & "') " & _
            "ORDER BY CDate(tbl_research_tbills.tbilldate)"

This statement is based on:
"tbl_research_tbills.tbilldate" column is char or varchar;
startedate, enddate are string.

If all of them are in "yyyy-MM-dd" format, such as "2006-04-26", that statement would work perfectly. If not, please show me your sample values of the column and variables, I will give you further instruction.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.