Re: Format() Function in MS SQL



sql guy123 (stoppal@xxxxxxxxxxx) writes:
> I'm pretty new to MS SQL,
>
> My problem is setting ....
>
>=Format$(Date(),"mm" & "/1/" & "YYYY")
>
> (Which is from my MS ACCESS database)
>
> as my default value in MS SQL. How can I do this since format() does
> not seem to be a function that is in MS SQL. The above function works
> great in MS ACCESS, but not in MS SQL.

There are *huge* differences between Access and SQL Server. First of all
SQL Server is a server-only program, while in Access, you have a mixup
of client and database in the same package. But there are also big
differences between Access and SQL Server in the SQL dialect.

For formating dates, you use the convert function:

SELECT convert(varchar, getdate(), nnn)

where nnn is a format code, each format code giving a different format. And
there is no room for customer format. Look up the topic CAST and CONVERT in
Books Online to see the available format codes.

Best practice, though, is to return dates as is from SQL Server, and do
the formatting in the client, so the user's regional settings can be
taken into account.


--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: Inserting regional settings specific data into sql server
    ... All EU countries withouth the two English speaking use the format dd-MM-yy ... By using the parameters, while the program is in the right culture setting, ... than all those formats results using SQLparameters in the way the SQL server ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Inserting regional settings specific data into sql server
    ... Italianyou will observe that the settings used are 10/02/2006 ... it a better idea to Format it using the string format functions or a very ... into the sql database.Sorry to bug the shorts off you but u now have context ... By using the parameters, while the program is in the right culture setting, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: user wants access
    ... I would strongly recommend you read Books Online for this information. ... the db_securityadmin fixed database role. ... Looking for a SQL Server replication book? ...
    (microsoft.public.sqlserver.server)
  • Re: How do I convert my dates to string in ADO
    ... and then format it the way I want it in the ... is easier to use Sql To do this. ... Microsoft SQL Server, ... file from a .CSV file which happens to be a report. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Moving a VBA function to SQL server
    ... SQL is a set-based language. ... "String Functions " in Books Online. ... This will produce a job header formatted like this: ... The format he specifies is stored in table 'Settings' - field 'JobHdrMask' ...
    (comp.databases.ms-access)