Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Format() Function in MS SQL
HI,

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.

thanks


Report this thread to moderator Post Follow-up to this message
Old Post
sql guy123
11-29-05 01:25 AM


Re: Format() Function in MS SQL
sql guy123 (stoppal@hotmail.com)  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@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Report this thread to moderator Post Follow-up to this message
Old Post
Erland Sommarskog
11-29-05 01:25 AM


Re: Format() Function in MS SQL
I'm actually not really trying to format the date, but rather set the
default value of the column(field) to the first day of the month.

example: 1/1/2005, 2/1/2005, 3/1/2005 etc...

What is the best way to get the default value in MS SQL to be the first
day of the month?


Report this thread to moderator Post Follow-up to this message
Old Post
sql guy123
11-29-05 08:23 AM


Re: Format() Function in MS SQL
try
 =CONVERT(smalldateti
me,DATENAME(m, GETDATE()) + ' 1,' + DATENAME(yy,
GETDATE()))

HTH,
Stu


Report this thread to moderator Post Follow-up to this message
Old Post
Stu
11-29-05 08:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 03:49 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006