Showing posts with label due. Show all posts
Showing posts with label due. Show all posts

Thursday, March 22, 2012

Computed column question

I have a SQL table that maintains a field on the status of a report being completed.

I have in the record the date the report is due (DateDue)

I also have a field called DaysLate which I have set to be a calculated field with formula:

DATEDIFF(dd, DateDue, GETDATE())

Thsi works but when the report is *not* late I'd like this to be null is there I way I can do this conditional calculation in a calculated field?

Regards

Cvive

CASE WHEN {Your formula}<0 THEN NULL ELSE {Your formula} END

|||

Many thanks for that - that did the job perfectly.

Clive

Wednesday, March 7, 2012

Complex relationship

Due to choices beyond my control I am faced with a tough bit of SQL to compose.

I have four tables. Let us callt hem A, B, C & D.

Table B has had it's content wholesale copied into table A. Table A is dynamic and changes table B will never change.

Table B has a non explicite (unenforced) but real one to many relationship to C.

[B] --< [C]

This is due to a unique number for each record within each row of B and none, one or many instances of that number within C.

These number DID NOT copy to A from B as A will be useing an autonumber instead.

The relationship between A and B is the presence of something the developers chose to call the SB_Key it is is 99.9% unique with odds of arround 1 in 1000 chance of two identical values in two different fields. However to get SB_Key duplication the records have to be made in the same second in the same table on the same day (etc) so for our purposes they are all different as no user I know can type taht fast.

[A] -- [B] A has a one to one relationship to B

Now we come to table D. D has had the content of C copied into it. C is static and D is dynamic.

Again the SB_Key is the one to one link between the tables.

[C] -- [D] C has a one to one relation ship with D.

So far all of these relationships are known only to the programmers and are not explicit.

Further tables B and C are in another database file altogeather!

[A] -- [B] --< [C] -- [D]

No comes the bit with which I am haveing some trouble.

[A] --< [D] A should have a one to many relationship with D. The relationship of A to D must match the relationship from B to C.

The data is in place and the plan is to "run an update Query" to replace the Foregn Key in table D with the correct autonumber-generated value from table A based on the relationship between B and C.

I can not whoever seem to comeup with the SQL that will do this.

If I have to I can create the SQL dynamicly in VBa code and create VBa functions to go get information.

However there is a lot of data and the more functions the slower the system. It will be run on PCs ranging from Pentium II to 3 Gig Athlon XP and it is vital that the computer not crash or appear to crash and cause the user to press reset (thus corrupting thier data).

Help.Sounds like you want to do this:

update d
set a_id =
( select a_id
from a, b, c
where a.sb_key = b.sb_key
and b.b_id = c.b_id
and c.sb_key = d.sb_key
);

Sunday, February 19, 2012

Complete newbie to replication, have a question

We have had a server in LocationA for quite some time. The need arose
recently to have a server setup in LocationB due to some bandwidth issues.
LocationB was given a snapshot of the DB @. LocationA when it was first
setup. However, both machines will need to have the same data as both are
used in a production environment. I will probably want to do this nightly.
I have read a lot of posts and webistes, but still am semi in the dark.
About the only thing i've figured out (i think) is that I will need to do
some sort of merge replicaiton.
What do I need to do to get started, a link to a HOW TO for a smiliar setup
would be great. I have read a bit and some mention having a 3rd server, do
i need a 3rd server as the final merged server? I guess more importantly is
a 3rd server an optimal solution?
Any help would be greatly appreciated.
Forgot to mention, I am running SQL Server 2000 on both servers.
"Lucas Graf" <lgraf2000@.comcast.net> wrote in message
news:OjZ0E0bQGHA.5296@.TK2MSFTNGP09.phx.gbl...
> We have had a server in LocationA for quite some time. The need arose
> recently to have a server setup in LocationB due to some bandwidth issues.
> LocationB was given a snapshot of the DB @. LocationA when it was first
> setup. However, both machines will need to have the same data as both are
> used in a production environment. I will probably want to do this
> nightly.
> I have read a lot of posts and webistes, but still am semi in the dark.
> About the only thing i've figured out (i think) is that I will need to do
> some sort of merge replicaiton.
> What do I need to do to get started, a link to a HOW TO for a smiliar
> setup would be great. I have read a bit and some mention having a 3rd
> server, do i need a 3rd server as the final merged server? I guess more
> importantly is a 3rd server an optimal solution?
> Any help would be greatly appreciated.
>
|||In merge replication you will have Distributor, Publisher and Subscriber.
They are different roles for a replication setup but they can be on the same
physical machine. I think the 3rd server you mentioned is distributor. You
can setup the distributor on the same server with the publisher, so you
don't need a third machine.
Yi Chen
"Lucas Graf" <lgraf2000@.comcast.net> wrote in message
news:OjZ0E0bQGHA.5296@.TK2MSFTNGP09.phx.gbl...
> We have had a server in LocationA for quite some time. The need arose
> recently to have a server setup in LocationB due to some bandwidth issues.
> LocationB was given a snapshot of the DB @. LocationA when it was first
> setup. However, both machines will need to have the same data as both are
> used in a production environment. I will probably want to do this
> nightly.
> I have read a lot of posts and webistes, but still am semi in the dark.
> About the only thing i've figured out (i think) is that I will need to do
> some sort of merge replicaiton.
> What do I need to do to get started, a link to a HOW TO for a smiliar
> setup would be great. I have read a bit and some mention having a 3rd
> server, do i need a 3rd server as the final merged server? I guess more
> importantly is a 3rd server an optimal solution?
> Any help would be greatly appreciated.
>
|||Ok. That makes sense.
I have been messing around trying to set it up today, and am still lost.
Currently the 2 servers are out of sync. Both have data the other doesn't.
What do I need to do to get them both to have the same data now, and then
keep them replciating from here on out?
"Yi Chen [MSFT]" <yiche@.online.microsoft.com> wrote in message
news:%23o7jSucQGHA.1204@.TK2MSFTNGP12.phx.gbl...
> In merge replication you will have Distributor, Publisher and Subscriber.
> They are different roles for a replication setup but they can be on the
> same physical machine. I think the 3rd server you mentioned is
> distributor. You can setup the distributor on the same server with the
> publisher, so you don't need a third machine.
> Yi Chen
> "Lucas Graf" <lgraf2000@.comcast.net> wrote in message
> news:OjZ0E0bQGHA.5296@.TK2MSFTNGP09.phx.gbl...
>
|||Lucas Graf wrote:
> We have had a server in LocationA for quite some time. The need arose
> recently to have a server setup in LocationB due to some bandwidth issues.
> LocationB was given a snapshot of the DB @. LocationA when it was first
> setup. However, both machines will need to have the same data as both are
> used in a production environment. I will probably want to do this nightly.
> I have read a lot of posts and webistes, but still am semi in the dark.
> About the only thing i've figured out (i think) is that I will need to do
> some sort of merge replicaiton.
> What do I need to do to get started, a link to a HOW TO for a smiliar setup
> would be great. I have read a bit and some mention having a 3rd server, do
> i need a 3rd server as the final merged server? I guess more importantly is
> a 3rd server an optimal solution?
> Any help would be greatly appreciated.
|||Lucas,
presumably you have initialized the subscriber and are using merge
replication? If so, you just need to synchronize the subscriber to have the
data merged. You'll need to consider who should win conflicts (publisher by
default) and if conflicts should be allowed (filtering).
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||Ok.
I got this far and was tentative on going further. I will keep trucking and
see what else may come up that causes issues. Thanks for the help so far, I
hope to report back a positive experience.
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:%23ogHO4uQGHA.2628@.TK2MSFTNGP15.phx.gbl...
> Lucas,
> presumably you have initialized the subscriber and are using merge
> replication? If so, you just need to synchronize the subscriber to have
> the data merged. You'll need to consider who should win conflicts
> (publisher by default) and if conflicts should be allowed (filtering).
> Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>
|||I guess I am still confused w/the whole publisher/distributor thing.
Since I want both servers to merge both of their data are they both set to
publishers and distributors? Or is only 1 a publisher and both distributors
and subscribers?
So confused..
"Lucas Graf" <lgraf2000@.comcast.net> wrote in message
news:Ob$pMuzQGHA.2436@.TK2MSFTNGP11.phx.gbl...
> Ok.
> I got this far and was tentative on going further. I will keep trucking
> and see what else may come up that causes issues. Thanks for the help so
> far, I hope to report back a positive experience.
>
> "Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
> news:%23ogHO4uQGHA.2628@.TK2MSFTNGP15.phx.gbl...
>
|||Ok.
ServerA
I have set him to a Distributor, Publisher and set the Database i want to
publish to the other server as the "push" datatabase. All seems good on
ServerA.
ServerB
Not sure what to do here so its data gets pushed to ServerA to be merged
there as well. Everything I try i end up getting the error "You cannot
create a merge replicaion in database xxxc. The database contains one or
more merge subscritptions that are anonymous or that use the Priority of the
Publisher when resolving conflicts."
"Lucas Graf" <lgraf@.nvidia.com> wrote in message
news:uSQuaI8QGHA.5552@.TK2MSFTNGP14.phx.gbl...
>I guess I am still confused w/the whole publisher/distributor thing.
> Since I want both servers to merge both of their data are they both set to
> publishers and distributors? Or is only 1 a publisher and both
> distributors and subscribers?
> So confused..
>
> "Lucas Graf" <lgraf2000@.comcast.net> wrote in message
> news:Ob$pMuzQGHA.2436@.TK2MSFTNGP11.phx.gbl...
>
|||Maybe Bidirectional Transactional Replication is more what I am looking for?
"Lucas Graf" <lgraf@.nvidia.com> wrote in message
news:uSQuaI8QGHA.5552@.TK2MSFTNGP14.phx.gbl...
>I guess I am still confused w/the whole publisher/distributor thing.
> Since I want both servers to merge both of their data are they both set to
> publishers and distributors? Or is only 1 a publisher and both
> distributors and subscribers?
> So confused..
>
> "Lucas Graf" <lgraf2000@.comcast.net> wrote in message
> news:Ob$pMuzQGHA.2436@.TK2MSFTNGP11.phx.gbl...
>