显示标签为“exists”的博文。显示所有博文
显示标签为“exists”的博文。显示所有博文

2012年3月19日星期一

Any way to check if a log file (.txt) already exists before BCPing a file?

I want to have one log file for each task ran within a job. There are several tasks for each job that may be handled by different people so I would like to have a running log file on the network that can be checked by supervisors. I know how to creat the log file:

master..xp_cmdshell bcp "SELECT * FROM ##logFile" queryout "c:\log.txt"

Problem is next time a task is run, the original text file will get written over by the new one. I came up with a solution for that by using bcp to export a temporary log file, then append that file to my existing log file, then kill the temporary file and that works fine:

master..xp_cmdshell copy log_temp.txt + log.txt

The problem is the second command obviously fails if the main log file does not exist.

Ideally I would like to check to see if the log file exists, if not create it, if it does exist, append to it.

Having a master log table stored in SQL has been suggested and shot down. They want one text file for job ran.

Any help would be greatly appreciated.

Thanks.

Tim

Write VBScript code (for example) and run this in a SQLAgent job. Don't use xp_cmdshell for these sort of things. It is less flexible and a security vulnerability. It takes few lines of code in VBScript to check for file. Or you can write a CMD script and run it in a SQLAgent job.

2012年2月18日星期六

Any harm in changing nullability while a default exists for a colu

Hi,
In Microsoft SQL Server 2000 SP3 are there any potential drawbacks of
changing the table column nullability via the ALTER TABLE ALTER COLUMN while
a default is also defined for that column? If yes, what are they?
--
Many thanks,
OskarYou'll need to drop the default constraint before ALTER TABLE...ALTER COLUMN
and re-add the constraint afterwards.
Column nullability doesn't affect the behavior of the default constraint so
I'm not aware of any drawbacks. The default value is used only when the
column is not included in the column list of an INSERT statement. Of
course, an explicit NULL value will be permitted only when the column allows
nulls.
Hope this helps.
Dan Guzman
SQL Server MVP
"Oskar" <Oskar@.discussions.microsoft.com> wrote in message
news:D50EF76B-BF46-4B49-9AD9-07364BF75E8A@.microsoft.com...
> Hi,
> In Microsoft SQL Server 2000 SP3 are there any potential drawbacks of
> changing the table column nullability via the ALTER TABLE ALTER COLUMN
> while
> a default is also defined for that column? If yes, what are they?
> --
> Many thanks,
> Oskar
>|||Yes, but when I needed to change a column from NULL to NOT NULL in one of the
tables and a default was defined on that column, the SQL Server parser didn't
complain about that. It allowed me to change the definition without any
warnings. Does this mean that I've done it in the wrong way? If yes, why?
--
Many thanks,
Oskar
"Dan Guzman" wrote:
> You'll need to drop the default constraint before ALTER TABLE...ALTER COLUMN
> and re-add the constraint afterwards.
> Column nullability doesn't affect the behavior of the default constraint so
> I'm not aware of any drawbacks. The default value is used only when the
> column is not included in the column list of an INSERT statement. Of
> course, an explicit NULL value will be permitted only when the column allows
> nulls.
>
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Oskar" <Oskar@.discussions.microsoft.com> wrote in message
> news:D50EF76B-BF46-4B49-9AD9-07364BF75E8A@.microsoft.com...
> > Hi,
> > In Microsoft SQL Server 2000 SP3 are there any potential drawbacks of
> > changing the table column nullability via the ALTER TABLE ALTER COLUMN
> > while
> > a default is also defined for that column? If yes, what are they?
> >
> > --
> > Many thanks,
> > Oskar
> >
> >
>
>|||No, Oskar, you didn't do anything wrong. My comment about dropping and
re-adding the constraint applies when changing the column data type but not
when changing only column nullability. Sorry for the confusion.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Oskar" <Oskar@.discussions.microsoft.com> wrote in message
news:3049DDD6-BA64-4A17-BEB6-7B34B9C68D80@.microsoft.com...
> Yes, but when I needed to change a column from NULL to NOT NULL in one of
> the
> tables and a default was defined on that column, the SQL Server parser
> didn't
> complain about that. It allowed me to change the definition without any
> warnings. Does this mean that I've done it in the wrong way? If yes, why?
> --
> Many thanks,
> Oskar
> "Dan Guzman" wrote:
>> You'll need to drop the default constraint before ALTER TABLE...ALTER
>> COLUMN
>> and re-add the constraint afterwards.
>> Column nullability doesn't affect the behavior of the default constraint
>> so
>> I'm not aware of any drawbacks. The default value is used only when the
>> column is not included in the column list of an INSERT statement. Of
>> course, an explicit NULL value will be permitted only when the column
>> allows
>> nulls.
>>
>> --
>> Hope this helps.
>> Dan Guzman
>> SQL Server MVP
>> "Oskar" <Oskar@.discussions.microsoft.com> wrote in message
>> news:D50EF76B-BF46-4B49-9AD9-07364BF75E8A@.microsoft.com...
>> > Hi,
>> > In Microsoft SQL Server 2000 SP3 are there any potential drawbacks of
>> > changing the table column nullability via the ALTER TABLE ALTER COLUMN
>> > while
>> > a default is also defined for that column? If yes, what are they?
>> >
>> > --
>> > Many thanks,
>> > Oskar
>> >
>> >
>>

2012年2月16日星期四

Any embedded tool in win2003 or SSIS for extracting the files from ZIP

Who knows whether exists embedded tool in win2003 or SSIS for extracting the files from ZIP?

Thanks in advance.

SSIS can execute a command line zip utility to extract files.|||

Do u mean that it should use 3rd party tool(like winzip command line)?

I dont wanna do that cuz of commercial purpose.

I just wanna know any tool in windows 2003 server or something banding in the SSIS

|||You're going to have to use a 3rd party utility.