Showing posts with label default. Show all posts
Showing posts with label default. Show all posts

Tuesday, March 27, 2012

Can I find the default printer

I have successfully modified the routines from here http://msdn2.microsoft.com/en-us/library/ms252091(VS.80).aspx and can print OK on the Development machine but I have had to code the default printer name

I want to be able to get the users default printer and also set the orientation I don't know if this is possible in ASP

I have been able to get the default printer but cannot change the orientation any ideas?

To Get and Set the default Printer works OK
PrintDocument printDoc =newPrintDocument();
string printerName = printDoc.PrinterSettings.PrinterName;//Get the name
printDoc.PrinterSettings.PrinterName = printerName;//use the name

This below does not seem to work??
printDoc.PrinterSettings.DefaultPageSettings.Landscape =true;

|||

HI,jnc:

Try to change this line :

printDoc.PrinterSettings.DefaultPageSettings.Landscape =true;

To this:

printDoc.DefaultPageSettings.Landscape =true;

If i misunderstand you about your question, please feel free to correct me and i will try to help you with more information.

I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance

|||

Perfect timing, I was just revisiting this and your solution worked fine

Sunday, March 25, 2012

Can I do an "alter table add column", with an existing named default?

Hello folks,
Shouldn't I be able to do this? I'm not able to get the syntax to work
Alter table TableName add ColumnName tinyint not null default
DefaultZero
This works:
Alter table TableName add ColumnName tinyint not null default (0)
...but I need to immediately drop the default programatically, and for
that I need the default name, so I'd like to name it myself.
I tried this:
EXEC sp_unbindefault 'TableName .ColumnName'
but got the error "Cannot unbind from 'TableName .ColumnName'. Use
ALTER TABLE DROP CONSTRAINT.
I guess I could query the system tables to figure out the name, but
would prefer not to if I can avoid it.
thanks for any ideas!
SylviaHere's an example with the proper syntax:
ALTER TABLE TableName
ADD ColumnName tinyint NOT NULL
CONSTRAINT DF_TableName_ColumnName DEFAULT 0
Hope this helps.
Dan Guzman
SQL Server MVP
"Sylvia" <Puget4753@.yahoo.com> wrote in message
news:1116288687.747349.22520@.g47g2000cwa.googlegroups.com...
> Hello folks,
> Shouldn't I be able to do this? I'm not able to get the syntax to work
> Alter table TableName add ColumnName tinyint not null default
> DefaultZero
> This works:
> Alter table TableName add ColumnName tinyint not null default (0)
> ...but I need to immediately drop the default programatically, and for
> that I need the default name, so I'd like to name it myself.
> I tried this:
> EXEC sp_unbindefault 'TableName .ColumnName'
> but got the error "Cannot unbind from 'TableName .ColumnName'. Use
> ALTER TABLE DROP CONSTRAINT.
> I guess I could query the system tables to figure out the name, but
> would prefer not to if I can avoid it.
> thanks for any ideas!
> Sylvia
>|||thanks - this works perfectly!

Tuesday, March 20, 2012

Can I change the language settings after installation?

Hi All,

I have sql server 2005 dveloper edition installed on my XP pro. Both are English editions. I used the default language settings to install sql server 2005. The XP Pro has asian-language support installed and supports Chinese input.

I have tables with columns in nvarchar. But I can not input Chinese into the columns directly in the management studio or using sql statement.

How could I change the language so the Chinese chracaters being accepted?

Thanks a lot!

Gavin

You can change the collation sequence at the database, table, and column level. If you didn't specify any options, then the database will be created with your default collation sequence from the instance. If you change the collation sequence on the database or table to one compatible by the Chinese character set you are using, then you can input that data. You are going to need to drop and recreate the table since switching the collation sequence on the database doesn't automatically do so on the table.|||

Thanks Michael.

I remembered that it's not easy to do this in the previous versions (maybe I'm wrong?). So I think it is the same for 2005. When I was checking properties of the database, I noticed collation could be changed. I tried and it worked for me. I did not check the table and column level but I believe your are right. I may try them later.

Gavin

Can I change the default CSV extract to reporting services

I have been searching and found the answer to my problems in the XML string
sent from the reporting services engine on scheduled jobs. I know I need to
add a Noheader command and also change to ASCII.
I wondering how do I do this to scheduled jobs with in the reporting
services environment and schedule it to run each day with the extra device
parameters. The default I want for this report will be the same default for
all csv files so can I change something in the report engine or the CSV
extract defaults?
Current address I use is
http://report01/ReportServer?%2fDevelopment%2fEIS%2fEIS02+BSMPurchaseOrderExtract&rs:Format=CSV&rs:Command=Render&rc:Extension=txt&rc:NoHeader=true&rc:FieldDelimiter=&rc:Encoding=asciiI would love to know the answer to this because I have exactly the same
problem.
"John230873" wrote:
> I have been searching and found the answer to my problems in the XML string
> sent from the reporting services engine on scheduled jobs. I know I need to
> add a Noheader command and also change to ASCII.
> I wondering how do I do this to scheduled jobs with in the reporting
> services environment and schedule it to run each day with the extra device
> parameters. The default I want for this report will be the same default for
> all csv files so can I change something in the report engine or the CSV
> extract defaults?
> Current address I use is
> http://report01/ReportServer?%2fDevelopment%2fEIS%2fEIS02+BSMPurchaseOrderExtract&rs:Format=CSV&rs:Command=Render&rc:Extension=txt&rc:NoHeader=true&rc:FieldDelimiter=&rc:Encoding=ascii
>

Monday, March 19, 2012

Can I assign rowguid from the client code instead of using default newid()?

Do I have to use default newid() for the rowguid? I would prefer to pass a
sequential GUID from the client code instead.
Message posted via droptable.com
http://www.droptable.com/Uwe/Forums.aspx/sql-server-replication/200701/1
Or can I at least use newsequentialid() instead of newid() as the ROWGUID
default?
Message posted via droptable.com
http://www.droptable.com/Uwe/Forums.aspx/sql-server-replication/200701/1
|||Alex,
Yes,
CREATE TABLE dbo.Table1
(
test uniqueidentifier NOT NULL ROWGUIDCOL
) ON [PRIMARY]
ALTER TABLE dbo.Table1 ADD CONSTRAINT
DF_Table1_test DEFAULT (newid()) FOR test
-- Bill
"Alex via droptable.com" <no@.spam.pls> wrote in message
news:6bd9f60658969@.uwe...
> Or can I at least use newsequentialid() instead of newid() as the ROWGUID
> default?
> --
> Message posted via droptable.com
> http://www.droptable.com/Uwe/Forums.aspx/sql-server-replication/200701/1
>
|||Thank you for your response. It seems your code is still using newid(), but
anyway it is not what I was asking. The MS documentation says that one can
create replication ROWGUID column manually as long as it have the following
characteristics:
* The data type as UNIQUEIDENTIFIER.
* The default as NEWID().
* The ROWGUIDCOL property.
* A unique index on the column.
My questions are:
1. Can I use newsequentialid() instead of newid() ?
2. Can I supply GUID from my client code instead of using this default value?
I am interested in transactional replication model with updating subscribers.
AlterEgo wrote:[vbcol=seagreen]
>Alex,
>Yes,
>CREATE TABLE dbo.Table1
> (
> test uniqueidentifier NOT NULL ROWGUIDCOL
> ) ON [PRIMARY]
>ALTER TABLE dbo.Table1 ADD CONSTRAINT
> DF_Table1_test DEFAULT (newid()) FOR test
>-- Bill
Message posted via droptable.com
http://www.droptable.com/Uwe/Forums.aspx/sql-server-replication/200701/1

Can i add SQL statement to Parameter Fields?

Hi,
I am new to Crystal Reports. May i know can i add SQL statement to parameter fields under setting default values?
WillyYes, you can add SQL statement, but the statement, is a litlle diferent... not much.
Menu -> Report -> Select Expert ->
Click Show formula >>> then hit the button Formula editor...

Hi,

I am new to Crystal Reports. May i know can i add SQL statement to parameter fields under setting default values?

Willy|||Thanks a lot

Sunday, March 11, 2012

Can default Isolation Level be changed?

Hello,
Just wondering if the default Isolation Level can be changed for an
entire database (or server) instead of having to issue a 'SET ISOLATION
LEVEL...' for a connection.
Many thanks,
Syd.
No, you will have to change it at the connection level.
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Sydney Delieu" <syddel@.hotmail.com> wrote in message
news:OzlpNXxLEHA.1156@.TK2MSFTNGP09.phx.gbl...
Hello,
Just wondering if the default Isolation Level can be changed for an
entire database (or server) instead of having to issue a 'SET ISOLATION
LEVEL...' for a connection.
Many thanks,
Syd.

Can default Isolation Level be changed?

Hello,
Just wondering if the default Isolation Level can be changed for an
entire database (or server) instead of having to issue a 'SET ISOLATION
LEVEL...' for a connection.
Many thanks,
Syd.No, you will have to change it at the connection level.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Sydney Delieu" <syddel@.hotmail.com> wrote in message
news:OzlpNXxLEHA.1156@.TK2MSFTNGP09.phx.gbl...
Hello,
Just wondering if the default Isolation Level can be changed for an
entire database (or server) instead of having to issue a 'SET ISOLATION
LEVEL...' for a connection.
Many thanks,
Syd.

Can default Isolation Level be changed?

Hello,
Just wondering if the default Isolation Level can be changed for an
entire database (or server) instead of having to issue a 'SET ISOLATION
LEVEL...' for a connection.
Many thanks,
Syd.No, you will have to change it at the connection level.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Sydney Delieu" <syddel@.hotmail.com> wrote in message
news:OzlpNXxLEHA.1156@.TK2MSFTNGP09.phx.gbl...
Hello,
Just wondering if the default Isolation Level can be changed for an
entire database (or server) instead of having to issue a 'SET ISOLATION
LEVEL...' for a connection.
Many thanks,
Syd.

Can default and named instance co-exist?

I have 2 Windows 2003 servers running SQL2000. They each have separate
databases. I am in the process of clustering these 2 machines together. I
have purchased a shared external SCSI PowerVault appliance to put the quorom
and the shared databases on. I want to create a Virtual SQL server using
these 2 machines and put their separate databases on the virtual server. My
question is:
Do I have to uninstall SQL server on each machine before I install the
virtual server? If I have to I would have to restore my databases to the new
virtual server
Or can I just install a new named instance of SQL server - choosing the
virtual server in the setup? If I can do this - it would be a lot easier
moving my databases over to the new server.
If I can just create a new virtual server with leaving the original SQL in
tact - will the original still be available to my users if I decide not to
move all the databases over that day?
Is there one way that is better than the other?
1. If you want to use the exact same instance names, uninstall/reinstall for
clustering is needed. If not, you can just virtualize your new instance and
migrate data.
2. Consider reading through this kb for some details
http://support.microsoft.com/kb/224071
3. Your original instance will continue to run while you're installing a new
instance on the same node.
The bottom line, I would create a new instance and ensure it's up and
running before tinkering with the original.
-oj
"Amy Lewis" <AmyLewis@.discussions.microsoft.com> wrote in message
news:223F3934-2F36-4A2D-B5D5-D860055AE5E7@.microsoft.com...
>I have 2 Windows 2003 servers running SQL2000. They each have separate
> databases. I am in the process of clustering these 2 machines together.
> I
> have purchased a shared external SCSI PowerVault appliance to put the
> quorom
> and the shared databases on. I want to create a Virtual SQL server using
> these 2 machines and put their separate databases on the virtual server.
> My
> question is:
> Do I have to uninstall SQL server on each machine before I install the
> virtual server? If I have to I would have to restore my databases to the
> new
> virtual server
> Or can I just install a new named instance of SQL server - choosing the
> virtual server in the setup? If I can do this - it would be a lot easier
> moving my databases over to the new server.
> If I can just create a new virtual server with leaving the original SQL in
> tact - will the original still be available to my users if I decide not to
> move all the databases over that day?
> Is there one way that is better than the other?
|||Each instance of SQL Server requires its own shared disk. You can install
either 1 default instance and 15 named instances or up to 16 named
instances, but each must have its own shared drive. All drives must have a
drive letter, no mount points allowed. For existing nonclustered instances,
if you move the data files to a shared drive then you will have the option
during setup to upgrade the standalone instance to a virtual/clustered
instance (assuming you're using the Enterprise Edition setup).
Cindy Gross, MCDBA, MCSE
http://cindygross.tripod.com
This posting is provided "AS IS" with no warranties, and confers no rights.

Thursday, March 8, 2012

Can Create default instance with April CTP

First, it was a nightmare to get it installed. Multiple installs,uninstalls, deleted (really renamed) directories, and cleaned registries.

It gets an error that the connection was refused. It works fine for a named instance.

Since all of the MSSQLServer registry entries are new, I don't think it is there. And all are done with the service Local Account. So I think the problem must be in the TCP/IP configuration referring to an old installation.

What is the problem? Is there a reference to all of these registry entries.

Thanks,

DavidIt's very difficult to provide you an answer given the information you provided. Are you trying to access the instance remotely or locally? By default, TCP is off. To turn on remote connectivity you can use either SQL Configuration Manager or SQL Server Surface Area Configuration Manager.

Dan

"This posting is provided "AS IS" with no warranties, and confers no rights"|||This occurs during the installation, so it is before the utilities are available. What communications method does the setup program use that can be refused. It is only refused for the default instance.|||Are you saying this works if you install a named instance? That's strange. Can you grab the log files from: %Program Files%\Microsoft SQL Server\90\Setup Bootstrap\log\files\*.log. You can zip the files before attaching them.

Thanks,
Dan|||Hi David

Probably setup is finding an default instance in the machine. I suggest that you uninstall previous build using the command line:

Start /wait D:\SQLDEV_CTP4\setup.exe /qb REMOVE=ALL
Start /wait msiexec /qb /X D:\SQLDEV_CTP4\Setup\sqlncli.msi
Start /wait D:\SQLDEV_CTP4\redist\2.0\dotnetfx.exe /q:a /c:"install /qu"

where D:\SQLDEV_CTP4 is the way for which you it extracted the of setup files.

Another option is to use Build Uninstall Wizard (\Setup Tools\Build Uninstall Wizard),but still I think that command line is more efficient to remove one previous build.
regards
Nilton Pinheiro

|||Sorry to say, I've got this exact same situation, and the above doesn't fix the problem.

Can Create default instance with April CTP

First, it was a nightmare to get it installed. Multiple installs,uninstalls, deleted (really renamed) directories, and cleaned registries.

It gets an error that the connection was refused. It works fine for a named instance.

Since all of the MSSQLServer registry entries are new, I don't think it is there. And all are done with the service Local Account. So I think the problem must be in the TCP/IP configuration referring to an old installation.

What is the problem? Is there a reference to all of these registry entries.

Thanks,

DavidIt's very difficult to provide you an answer given the information you provided. Are you trying to access the instance remotely or locally? By default, TCP is off. To turn on remote connectivity you can use either SQL Configuration Manager or SQL Server Surface Area Configuration Manager.

Dan

"This posting is provided "AS IS" with no warranties, and confers no rights"|||This occurs during the installation, so it is before the utilities are available. What communications method does the setup program use that can be refused. It is only refused for the default instance.|||Are you saying this works if you install a named instance? That's strange. Can you grab the log files from: %Program Files%\Microsoft SQL Server\90\Setup Bootstrap\log\files\*.log. You can zip the files before attaching them.

Thanks,
Dan|||Hi David

Probably setup is finding an default instance in the machine. I suggest that you uninstall previous build using the command line:

Start /wait D:\SQLDEV_CTP4\setup.exe /qb REMOVE=ALL
Start /wait msiexec /qb /X D:\SQLDEV_CTP4\Setup\sqlncli.msi
Start /wait D:\SQLDEV_CTP4\redist\2.0\dotnetfx.exe /q:a /c:"install /qu"

where D:\SQLDEV_CTP4 is the way for which you it extracted the of setup files.

Another option is to use Build Uninstall Wizard (\Setup Tools\Build Uninstall Wizard),but still I think that command line is more efficient to remove one previous build.
regards
Nilton Pinheiro

|||Sorry to say, I've got this exact same situation, and the above doesn't fix the problem.

Wednesday, March 7, 2012

Can connect to only One instance from another computer

We can only connect to only 1 instance, either the default localhost or the
named instance from another client.
For example on my computer the other client can connect to the localhost and
the other instance name such as server\instancenames cannot be connected. On
the other computer that does not have the default instance, the client can
only connect to one instance such as server\instancename.
The error message is the same as when sql cannot connect.
Mike
What version, edition of SQL Server? What is the exact error
message? What are you using to try to connect - application,
SQL Tools, DSN? Did you check for what instances are
running? The clients that can't connect to a named instance
- did you check their MDAC versions? Can you connect to
default and named instances when on the box where the
instances are running?
-Sue
On Thu, 23 Mar 2006 07:00:29 -0800, Mike9900
<Mike9900@.discussions.microsoft.com> wrote:

>We can only connect to only 1 instance, either the default localhost or the
>named instance from another client.
>For example on my computer the other client can connect to the localhost and
>the other instance name such as server\instancenames cannot be connected. On
>the other computer that does not have the default instance, the client can
>only connect to one instance such as server\instancename.
>The error message is the same as when sql cannot connect.

Can connect to only One instance from another computer

We can only connect to only 1 instance, either the default localhost or the
named instance from another client.
For example on my computer the other client can connect to the localhost and
the other instance name such as server\instancenames cannot be connected. On
the other computer that does not have the default instance, the client can
only connect to one instance such as server\instancename.
The error message is the same as when sql cannot connect.
MikeWhat version, edition of SQL Server? What is the exact error
message? What are you using to try to connect - application,
SQL Tools, DSN? Did you check for what instances are
running? The clients that can't connect to a named instance
- did you check their MDAC versions? Can you connect to
default and named instances when on the box where the
instances are running?
-Sue
On Thu, 23 Mar 2006 07:00:29 -0800, Mike9900
<Mike9900@.discussions.microsoft.com> wrote:

>We can only connect to only 1 instance, either the default localhost or the
>named instance from another client.
>For example on my computer the other client can connect to the localhost an
d
>the other instance name such as server\instancenames cannot be connected. O
n
>the other computer that does not have the default instance, the client can
>only connect to one instance such as server\instancename.
>The error message is the same as when sql cannot connect.

Friday, February 10, 2012

Calling user-created functions with default values

The documentation talks about default values, but gives no examples. I'm
trying to get this to work...
ALTER FUNCTION FirstDayOfYear(@.date datetime = getdate) RETURNS datetime
BEGIN
RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
END
They say you need to pass in "default", but I can't figure it out. I tried...
select dbo.FirstDayOfYear(default)
select default dbo.FirstDayOfYear()
select dbo.FirstDayOfYear() default
Any pointers?
Maury
I do not know why SQL Server let us create the function with the keyword
GETDATE as a parameter's default value. GETDATE is a function, so it should
be:
...
@.date datetime = getdate()
...
but then sql server give an error and this make sense. Try using a number
and you will see that it works (using default keyword when you call the
function).
alter FUNCTION FirstDayOfYear(
@.date datetime = 32500
)
RETURNS datetime
as
BEGIN
RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
END
go
select dbo.FirstDayOfYear(default)
go
I think you have to get rid of the default and allways pass a value to this
function.
AMB
"Maury Markowitz" wrote:

> The documentation talks about default values, but gives no examples. I'm
> trying to get this to work...
> ALTER FUNCTION FirstDayOfYear(@.date datetime = getdate) RETURNS datetime
> BEGIN
> RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
> END
> They say you need to pass in "default", but I can't figure it out. I tried...
> select dbo.FirstDayOfYear(default)
> select default dbo.FirstDayOfYear()
> select dbo.FirstDayOfYear() default
> Any pointers?
> Maury
|||That's actually looking for the string, 'getdate' -- actually calling the
GETDATE function requires parens (GETDATE()) -- however, SQL Server will not
accept that (I'm not sure why). You'll have to actually call the function
with GETDATE() as the argument to do what you need.
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:24DEC598-40A2-491E-A975-D5E9026BD10D@.microsoft.com...
> The documentation talks about default values, but gives no examples. I'm
> trying to get this to work...
> ALTER FUNCTION FirstDayOfYear(@.date datetime = getdate) RETURNS datetime
> BEGIN
> RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
> END
> They say you need to pass in "default", but I can't figure it out. I
tried...
> select dbo.FirstDayOfYear(default)
> select default dbo.FirstDayOfYear()
> select dbo.FirstDayOfYear() default
> Any pointers?
> Maury
|||"Adam Machanic" wrote:

> That's actually looking for the string, 'getdate' -- actually calling the
> GETDATE function requires parens (GETDATE()) -- however, SQL Server will not
> accept that (I'm not sure why). You'll have to actually call the function
> with GETDATE() as the argument to do what you need.
Got it. It doesn't really need to have this feature -- a default that is --
but it would make the callee syntax a little nicer.
Maury

Calling user-created functions with default values

The documentation talks about default values, but gives no examples. I'm
trying to get this to work...
ALTER FUNCTION FirstDayOfYear(@.date datetime = getdate) RETURNS datetime
BEGIN
RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
END
They say you need to pass in "default", but I can't figure it out. I tried..
.
select dbo.FirstDayOfYear(default)
select default dbo.FirstDayOfYear()
select dbo.FirstDayOfYear() default
Any pointers?
MauryI do not know why SQL Server let us create the function with the keyword
GETDATE as a parameter's default value. GETDATE is a function, so it should
be:
...
@.date datetime = getdate()
...
but then sql server give an error and this make sense. Try using a number
and you will see that it works (using default keyword when you call the
function).
alter FUNCTION FirstDayOfYear(
@.date datetime = 32500
)
RETURNS datetime
as
BEGIN
RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
END
go
select dbo.FirstDayOfYear(default)
go
I think you have to get rid of the default and allways pass a value to this
function.
AMB
"Maury Markowitz" wrote:

> The documentation talks about default values, but gives no examples. I'm
> trying to get this to work...
> ALTER FUNCTION FirstDayOfYear(@.date datetime = getdate) RETURNS datetime
> BEGIN
> RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
> END
> They say you need to pass in "default", but I can't figure it out. I tried
..
> select dbo.FirstDayOfYear(default)
> select default dbo.FirstDayOfYear()
> select dbo.FirstDayOfYear() default
> Any pointers?
> Maury|||That's actually looking for the string, 'getdate' -- actually calling the
GETDATE function requires parens (GETDATE()) -- however, SQL Server will not
accept that (I'm not sure why). You'll have to actually call the function
with GETDATE() as the argument to do what you need.
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:24DEC598-40A2-491E-A975-D5E9026BD10D@.microsoft.com...
> The documentation talks about default values, but gives no examples. I'm
> trying to get this to work...
> ALTER FUNCTION FirstDayOfYear(@.date datetime = getdate) RETURNS datetime
> BEGIN
> RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
> END
> They say you need to pass in "default", but I can't figure it out. I
tried...
> select dbo.FirstDayOfYear(default)
> select default dbo.FirstDayOfYear()
> select dbo.FirstDayOfYear() default
> Any pointers?
> Maury|||"Adam Machanic" wrote:

> That's actually looking for the string, 'getdate' -- actually calling the
> GETDATE function requires parens (GETDATE()) -- however, SQL Server will n
ot
> accept that (I'm not sure why). You'll have to actually call the function
> with GETDATE() as the argument to do what you need.
Got it. It doesn't really need to have this feature -- a default that is --
but it would make the callee syntax a little nicer.
Maury

Calling user-created functions with default values

The documentation talks about default values, but gives no examples. I'm
trying to get this to work...
ALTER FUNCTION FirstDayOfYear(@.date datetime = getdate) RETURNS datetime
BEGIN
RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
END
They say you need to pass in "default", but I can't figure it out. I tried...
select dbo.FirstDayOfYear(default)
select default dbo.FirstDayOfYear()
select dbo.FirstDayOfYear() default
Any pointers?
MauryI do not know why SQL Server let us create the function with the keyword
GETDATE as a parameter's default value. GETDATE is a function, so it should
be:
...
@.date datetime = getdate()
...
but then sql server give an error and this make sense. Try using a number
and you will see that it works (using default keyword when you call the
function).
alter FUNCTION FirstDayOfYear(
@.date datetime = 32500
)
RETURNS datetime
as
BEGIN
RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
END
go
select dbo.FirstDayOfYear(default)
go
I think you have to get rid of the default and allways pass a value to this
function.
AMB
"Maury Markowitz" wrote:
> The documentation talks about default values, but gives no examples. I'm
> trying to get this to work...
> ALTER FUNCTION FirstDayOfYear(@.date datetime = getdate) RETURNS datetime
> BEGIN
> RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
> END
> They say you need to pass in "default", but I can't figure it out. I tried...
> select dbo.FirstDayOfYear(default)
> select default dbo.FirstDayOfYear()
> select dbo.FirstDayOfYear() default
> Any pointers?
> Maury|||That's actually looking for the string, 'getdate' -- actually calling the
GETDATE function requires parens (GETDATE()) -- however, SQL Server will not
accept that (I'm not sure why). You'll have to actually call the function
with GETDATE() as the argument to do what you need.
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:24DEC598-40A2-491E-A975-D5E9026BD10D@.microsoft.com...
> The documentation talks about default values, but gives no examples. I'm
> trying to get this to work...
> ALTER FUNCTION FirstDayOfYear(@.date datetime = getdate) RETURNS datetime
> BEGIN
> RETURN convert(datetime, '1/1/' + convert(varchar, YEAR(@.date)))
> END
> They say you need to pass in "default", but I can't figure it out. I
tried...
> select dbo.FirstDayOfYear(default)
> select default dbo.FirstDayOfYear()
> select dbo.FirstDayOfYear() default
> Any pointers?
> Maury|||"Adam Machanic" wrote:
> That's actually looking for the string, 'getdate' -- actually calling the
> GETDATE function requires parens (GETDATE()) -- however, SQL Server will not
> accept that (I'm not sure why). You'll have to actually call the function
> with GETDATE() as the argument to do what you need.
Got it. It doesn't really need to have this feature -- a default that is --
but it would make the callee syntax a little nicer.
Maury