Showing posts with label order. Show all posts
Showing posts with label order. Show all posts

Friday, March 30, 2012

Puzzle: dateadd workdays only

Hello Louis:
You wrote on Tue, 4 Jan 2005 15:11:01 -0600:
LD> First, why have a table named workDays that contains more than
LD> workdays?
In order to have it filled in not by myself but by HR person, using a nice
dialog with checkboxes.
...
LD> Third, this query seems to work, you can make it into a stored
LD> procedure :)
LD> declare @.f int
LD> declare @.D1 datetime
LD> set @.d1 = '2005-01-01'
LD> set @.f = 6
LD> select *
LD> from workdays
LD> where workday = 1
LD> and date > @.d1
LD> and (select count(*)
LD> from workdays as w
LD> where w.date <= workdays.date
LD> and date > @.d1
LD> and workday = 1) = @.f
the code is OK, but VERY slow. If you populate the table up to, say, 2050
and try it, you will see. Can you make a query that would deliver the result
in a second?
LD> Fourth, what is this for? Why specifically a one-query stored
LD> procedure?
As the subject says, it was a puzzle :-)
VadimOn Tue, 25 Jan 2005 11:38:53 -0600, Vadim Rapp wrote:
Hi Vadim,

> LD> Fourth, what is this for? Why specifically a one-query stored
> LD> procedure?
>As the subject says, it was a puzzle :-)
Ah - I *love* puzzles!

>the code is OK, but VERY slow. If you populate the table up to, say, 2050
>and try it, you will see. Can you make a query that would deliver the resul
t
>in a second?
Here's a query that is extremely fast if the number of workdays to add is
low. At my system, it can calculate 10 workdays ahead in less than 0.003
seconds, 100 workdays in 0.016 seconds, 1025 workdays in approx. 1 second
and 2000 workdays in under 4 seconds.
The time saving trick is to limit the search to dates in a qualifying
range: the date to be found will always be at least @.f days after the
starting date and never more than 1 and a half time @.f days after the
starting date (to which I add 3 extra days, to make sure I still get an
answer if the date submitted is a friday befor a wend that is
immediately followed by a holiday and @.f is 1). It should be possible to
reduce the range even further - e.g. by setting the lowest possible date
at start date + (1.4 * @.f) minus 1 or 2 to correct for low values of @.f,
but I don't want to do the maths required to get the "best" starting and
ending point.
The query uses a calendar table (http://www.aspfaq.com/show.asp?id=2519);
I did not test to see if a covering index would speed it up further.
select c1.dt
from dbo.Calendar AS c1
inner join dbo.Calendar AS c2
on c2.dt >= @.d1
and c2.dt < c1.dt
and c2.isWday = 1
and c2.isHoliday is null
where c1.isWday = 1
and c1.isHoliday is null
and c1.dt >= dateadd(day, @.f, @.d1)
and c1.dt <= dateadd(day, (@.f * 1.5) + 3, @.d1)
group by c1.dt
having count(*) = @.f
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||On Wed, 26 Jan 2005 00:25:52 +0100, Hugo Kornelis wrote:
(snip)
Woops - that was an incomplete copy/paste.
Here's the complete script:
declare @.f int
declare @.d1 smalldatetime
set @.d1 = '20050104'
set @.f = 2000
select c1.dt
from dbo.Calendar AS c1
inner join dbo.Calendar AS c2
on c2.dt >= @.d1
and c2.dt < c1.dt
and c2.isWday = 1
and c2.isHoliday is null
where c1.isWday = 1
and c1.isHoliday is null
and c1.dt >= dateadd(day, @.f, @.d1)
and c1.dt <= dateadd(day, (@.f * 1.5) + 3, @.d1)
group by c1.dt
having count(*) = @.f
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hello Hugo:
You wrote in conference microsoft.public.sqlserver.programming on Wed, 26
Jan 2005 00:25:52 +0100:
HK> The time saving trick is to limit the search to dates in a qualifying
HK> range:
<snip>
HK> and c1.dt >= dateadd(day, @.f, @.d1)
HK> and c1.dt <= dateadd(day, (@.f * 1.5) + 3, @.d1)
HK> group by c1.dt
Yes, that's what I did as well. I think a sufficiently accurate range is thi
s:
if we have 5 workdays in a w
and we have N holidays in a year,
then it's safe to take the range as
between
@.date1 * 7.0/5.0 + (7-5) and
@.date1 * 7.0/5.0 + (7-5) + N * ( @.F / 365 + 1 )
HK> Ah - I *love* puzzles!
ok... then here's another one:
Find the date of the last Friday without using CASE (and in one query, of
course). If today is Friday, the result should be today's date.
regards,
Vadim Rapp
Vadim Rapp Consulting|||On Tue, 25 Jan 2005 22:30:08 -0600, Vadim Rapp wrote:
(snip)
> HK> Ah - I *love* puzzles!
>ok... then here's another one:
>Find the date of the last Friday without using CASE (and in one query, of
>course). If today is Friday, the result should be today's date.
Hi Vadim,
That's a question I've seen popping up in the newsgroups several times
lately. There are lots of possible solutions, but most of them depend on a
specific setting of SET DATEFIRST, or use a Calendar table.
Here's a solution that is independant of DATEFIRST and that won't need a
Calendar table:
SELECT DATEADD( day,
(DATEDIFF (day, '20000107', CURRENT_TIMESTAMP) / 7) * 7,
'20000107')
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Wednesday, March 28, 2012

Put database in warm standby after changing it from read only?

We have a server at a disaster recovery site that was in warm standby. In
order for the server to be fully functional, we had to bring the databases
out of warm standby to install some client software that read the databases
of the standby server. While trying to put the databases back into warm
standby restoring the next log in sequence from the production server, I get
an error saying "Exclusive access could not be obtained because the database
is in use". However, the database is in single-user mode. When trying a
restore log command in SQL, I get an error "preceding restore operation did
not specify WITH NORECOVERY or WITH STANDBY. RESTORE LOG is terminating
abnormally.
Is there any way to get the database(s) back into warm standy mode without
having to set it up again from scratch?
Thanks,
RSNope. Once it is set to "normal" mode you have to restore a full backup
WITH STANDBY.
--
Keith
"RS" <rspen@.yahoo.com> wrote in message
news:%23y9Z2Y7eEHA.2764@.TK2MSFTNGP11.phx.gbl...
> We have a server at a disaster recovery site that was in warm standby. In
> order for the server to be fully functional, we had to bring the databases
> out of warm standby to install some client software that read the
databases
> of the standby server. While trying to put the databases back into warm
> standby restoring the next log in sequence from the production server, I
get
> an error saying "Exclusive access could not be obtained because the
database
> is in use". However, the database is in single-user mode. When trying a
> restore log command in SQL, I get an error "preceding restore operation
did
> not specify WITH NORECOVERY or WITH STANDBY. RESTORE LOG is terminating
> abnormally.
> Is there any way to get the database(s) back into warm standy mode without
> having to set it up again from scratch?
> Thanks,
> RS
>

Wednesday, March 21, 2012

purchase order query: very funny and challenge ^_^

i query a purchase order table, there is one column called PO_No, format: LP-0245111-0004

i make following statement to query: the middle code act as my id, using it search my records, the last 4 digit used to find the last purchase order number

SqlSelectCommand2.CommandText = "SELECT PO_No FROM [PURCHASE ORDER] WHERE PO_No Like '%" & GetYearCode() & "%' ORDER BY Right(PO_No, 4) DESC"

i checked my database, last record is LP-0545381-0300

in my debuging process, surprisingly found that selected record is LP-0545381-301 !

any one hav any suggestion? ^_^

I fail to see the humor here, but that's irrelevant. It's difficult to know the query behavior without knowing what GetYearCode() is supposed to return and how it relates to the data in your table. Also, why does your last record (LP-0545381-301) have only 3 digits at the end when your format suggests that it should contain 4 digits? Finally, what were you expecting the result to be?|||

database never had that record, but selected out, isnt it very funny...anyway, GetYearCode() will return the middle code as0545381, i also suprisingly why return 3 digit?!unreasonable, isnt it

what i expected result isLP-0545381-0300

Purchase "SQL Server Management Studio" full version?

We still run SQL Server 2000. We need access to the full version of "SQL Server Management Studio" in order to use the Red-Gate SQL Refactoring tool, without buying the full SQL Server 2005 system. (The Express version of Studio does not work with the Red-Gate tool.)

Can anyone advise if it is possible to get/buy (and if so, where) the full "SQL Server Management Studio" version? I can't see any links to it on the MS site.

TIA

Barry

Visual Studio 2005 Enterprise comes with SQL 2005 Developer.

http://www.microsoft.com/products/info/default.aspx?view=22&pcid=515c9859-958b-4433-b4f9-91f37258ca2f

|||

Amazon sells SQL Server 2005 Developer Edition for $42.00, which includes SQL Server Management Studio

http://www.amazon.com/Microsoft-SQL-Server-Developer-2005/dp/B000BHQ5JW/ref=pd_bbs_sr_1/102-8185052-9808937?ie=UTF8&s=software&qid=1172893384&sr=8-1

|||

As indicated above, the Developer Edition should work for your purposes -as long as it is ONLY used in the development environment.

However, if you 'touch' a production server with SSMS, you are out of license compliance.

Friday, March 9, 2012

Publishing from RS 2000 to RS 2005

I want to publishing many reports from RS 2000 to RS 2005. These reports have
several server parameters. In order to do it I have used the utility
RSScripter, but this application produces .rss and .cmd files for RS 2000. I
have modified their code to do to function them to publish to RS 2005. Does
exist another version of this utility to do this migration? Does exist
another manner to solve this issue?
Many thanksI prefer to deploy using the report designer. The utility you are speaking
of has a version that supports both 2000 and 2005.
http://www.sqldbatips.com/showarticle.asp?ID=62
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Pasquale" <Pasquale@.discussions.microsoft.com> wrote in message
news:40E876D4-4EE6-4236-A3B3-03EA3960FE3E@.microsoft.com...
>I want to publishing many reports from RS 2000 to RS 2005. These reports
>have
> several server parameters. In order to do it I have used the utility
> RSScripter, but this application produces .rss and .cmd files for RS 2000.
> I
> have modified their code to do to function them to publish to RS 2005.
> Does
> exist another version of this utility to do this migration? Does exist
> another manner to solve this issue?
> Many thanks|||I have tried the version 2.0.0.10 and I have downloaded the next version of
RSScripter. When I launch the cmd files produces for RS 2000 to publish to RS
2005 I have some errors if before I don't modified the scripts. In particular,
I can lost the server parameters of RS 2000 reports. Moreover, there are two
different manners between RS 2000 and RS 2005 to set the data source for a
report. I don't see any option inside RSScripter to produce rdl, rds and cmd
files to RS 2005 but reading RS 2000 reports.
"Bruce L-C [MVP]" wrote:
> I prefer to deploy using the report designer. The utility you are speaking
> of has a version that supports both 2000 and 2005.
> http://www.sqldbatips.com/showarticle.asp?ID=62
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Pasquale" <Pasquale@.discussions.microsoft.com> wrote in message
> news:40E876D4-4EE6-4236-A3B3-03EA3960FE3E@.microsoft.com...
> >I want to publishing many reports from RS 2000 to RS 2005. These reports
> >have
> > several server parameters. In order to do it I have used the utility
> > RSScripter, but this application produces .rss and .cmd files for RS 2000.
> > I
> > have modified their code to do to function them to publish to RS 2005.
> > Does
> > exist another version of this utility to do this migration? Does exist
> > another manner to solve this issue?
> >
> > Many thanks
>
>|||Ahh, it probably works mostly for moving between the same versions.
If you are going between RS 2000 and RS 2005 I suggest you do not do it this
way. Although RS 2005 will run RS 2000 reports I recommend that you convert
your reports to RS 2005 first. I had a few weird little problems that went
away once I did this.
To convert you have to pull up the report in RS2005 report designer, let it
convert and then save. It is a little bit of a pain but the process is
quick. I kept a copy of my RS 2000 version reports around.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Pasquale" <Pasquale@.discussions.microsoft.com> wrote in message
news:6ED58430-5A33-4DC5-B5EE-1C7FB9F1D8D5@.microsoft.com...
>I have tried the version 2.0.0.10 and I have downloaded the next version of
> RSScripter. When I launch the cmd files produces for RS 2000 to publish to
> RS
> 2005 I have some errors if before I don't modified the scripts. In
> particular,
> I can lost the server parameters of RS 2000 reports. Moreover, there are
> two
> different manners between RS 2000 and RS 2005 to set the data source for a
> report. I don't see any option inside RSScripter to produce rdl, rds and
> cmd
> files to RS 2005 but reading RS 2000 reports.
>
> "Bruce L-C [MVP]" wrote:
>> I prefer to deploy using the report designer. The utility you are
>> speaking
>> of has a version that supports both 2000 and 2005.
>> http://www.sqldbatips.com/showarticle.asp?ID=62
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "Pasquale" <Pasquale@.discussions.microsoft.com> wrote in message
>> news:40E876D4-4EE6-4236-A3B3-03EA3960FE3E@.microsoft.com...
>> >I want to publishing many reports from RS 2000 to RS 2005. These reports
>> >have
>> > several server parameters. In order to do it I have used the utility
>> > RSScripter, but this application produces .rss and .cmd files for RS
>> > 2000.
>> > I
>> > have modified their code to do to function them to publish to RS 2005.
>> > Does
>> > exist another version of this utility to do this migration? Does exist
>> > another manner to solve this issue?
>> >
>> > Many thanks
>>