Showing posts with label named. Show all posts
Showing posts with label named. 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

Putting commas between select statement values

Hello,

This may be a strange request, but I am going to ask about it anyways.

Say for example if I have a table named TEST and in the table there is a column named NUMBERS, such that it is like this:

NUMBERS
1
2
3
4

How could I use a select statement in a way that a comma would seperate every return value, such that if I go 'Select NUMBERS from TEST' I would get:

1,2,3,4

Instead of:

1
2
3
4

Any ideas?

ThanksThe numbers will still be as o column... but try:

SELECT CAST(numbers as varchar)+',' from TEST

Friday, March 23, 2012

Push Binaries after installation SQL Server 2000 virtual server

I forget to set Client Network Utility to Create a Named Pipes Alias for
installation of a named instance of SQL Server 2000 virtual server on a
Windows 2003-based cluster fails to push binaries to the other node. SQL
Server 2000 virtual server installed fine on the present node but was unable
to push the binaries to the other node.
I have corrected the Named Pipes Alias problem. Is there away to push the
binaries to the other node that the cluster we recognize?
Thanks,
Treat it like a failed node. Run the installer to remove then re-add the
node. BOL topic 'Maintaining a Failover Cluster' has details.
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"Joe K." <JoeK@.discussions.microsoft.com> wrote in message
news:6F653B39-BBAA-4619-AEBA-3B8B6AD87037@.microsoft.com...
> I forget to set Client Network Utility to Create a Named Pipes Alias for
> installation of a named instance of SQL Server 2000 virtual server on a
> Windows 2003-based cluster fails to push binaries to the other node. SQL
> Server 2000 virtual server installed fine on the present node but was
unable
> to push the binaries to the other node.
> I have corrected the Named Pipes Alias problem. Is there away to push the
> binaries to the other node that the cluster we recognize?
> Thanks,
>
|||The need to create the named pipes alias has nothing to do with pushing the
binaries. Without the alias setup cannot connect to SQL Server to run the
necessary scripts. Without the alias I would be suspect that SQL Server
successfully installed on either node. I would run a complet setup again.
Rand
This posting is provided "as is" with no warranties and confers no rights.

Wednesday, March 7, 2012

Publisher configuration problem

I am trying to configure a MS SQL Server 2000 named \\MSSQL_NEW as a
publisher but I keep getting this
error:
SQL Server Enterprise Manager can not configure 'MSSQL_NEW' as the
distributor for 'MSSQL_NEW'
Error 18483:
Could not connect to server 'MSSQL_NEW' because 'distributor_admin' is not
defined as a remote login at
the server.
I've verified that 'distributor_admin' exists and has sysadmin rights on the
server (MSSQL_NEW).
I noticed that when I execute, 'select @.@.servername', in QA, I get,
'MSSQL_OLD'. But my machine name is, 'MSSQL_NEW'
and name registered in EM is 'MSSQL_NEW'. Tried replacing the registration
'MSSQL_NEW' to 'MSSQL_OLD' but I get a
server does not exist or access denied error.
Will updating @.@.servername to 'MSSQL_NEW' solve my problem? How?
Any comments or suggestions will be highly appreciated. Thanks in advance.
...
Carlo,
please try this...
Use Master
go
Sp_DropServer 'MSSQL_OLD'
GO
Use Master
go
Sp_Addserver 'MSSQL_NEW', 'local'
GO
Stop and Start SQL Services
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||This is a tricky problem to solve.
I normally solve it by issuing a
sp_adddistributor and an sp_adddistributiondb procs.
These should work. Then when you go to replicate it will bomb. So disable
replication, and then re-enable it. It should work this time.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"CarloVino" <CarloVino@.discussions.microsoft.com> wrote in message
news:77815079-C1A6-477C-9794-391828479E38@.microsoft.com...
> I am trying to configure a MS SQL Server 2000 named \\MSSQL_NEW as a
> publisher but I keep getting this
> error:
> SQL Server Enterprise Manager can not configure 'MSSQL_NEW' as the
> distributor for 'MSSQL_NEW'
> Error 18483:
> Could not connect to server 'MSSQL_NEW' because 'distributor_admin' is not
> defined as a remote login at
> the server.
> I've verified that 'distributor_admin' exists and has sysadmin rights on
the
> server (MSSQL_NEW).
> I noticed that when I execute, 'select @.@.servername', in QA, I get,
> 'MSSQL_OLD'. But my machine name is, 'MSSQL_NEW'
> and name registered in EM is 'MSSQL_NEW'. Tried replacing the
registration
> 'MSSQL_NEW' to 'MSSQL_OLD' but I get a
> server does not exist or access denied error.
> Will updating @.@.servername to 'MSSQL_NEW' solve my problem? How?
> Any comments or suggestions will be highly appreciated. Thanks in
advance.
> --
> ...

Saturday, February 25, 2012

Publication doesn't show

To try out replication I have installed several instances of SQL server on a
single computer. With one default server and one named server merge
replication with pull subscription works fine. When I try to add a pull
subscription to an additional named server however, the publication does not
show in the list.
I tried removing the subscription and publication. Then I added the
publication. This makes the publication visible from both named servers when
I use the pull subscription wizard. But when I finish the wizard to add a
pull subscription to any of the servers, this makes the publication not
appear when I try to create a pull subscription to the other server. If I
only delete the subscription (not the publication), the publication does not
show up from any of the named servers.
The publication is configured to allow anonymous subscriptions.
Additionally, I use the same password for the sa account on all servers, so I
think the publication should be accesible to the login used to connect to the
named servers. Any ideas why the publication does not show up in the pull
subscription wizard?
/Daniel
I still don't know what the problem was, but I worked around it by first
creating a push subscription to the server from which I wanted to create a
pull subscription. This, for some reason, made the publication visible in the
pull subscription wizard.