Showing posts with label product. Show all posts
Showing posts with label product. Show all posts

Sunday, March 11, 2012

Back & Restore of Multiple Databases

Hey all,

I was wondering if I could get some help on something thats got me really stuck!

At the moment we have in our product some SQL scripts that will backup & restore a database whenever required.

We've now added another database (an audit database) so we need to change those scripts to include this database.

The backup script seems fairly easy to change as ive added another 'BACKUP DATABASE' line that points to the same file.

The problem I am having is that when it comes to restore the 2 databases I get a whole load of errors, most of them complaining that the '.mdf' & 'log' files can't be overritten because they are already in use by the previous database (since I restore the 'data' database first and then the 'audit' database)

I've tried the 'MOVE' command but it doesn't seem to support the 'RESTORE' option?

Is there anyway I can get the backup to retain the '.mdf' & '.log' file locations so that the restore simply puts them back in the same place or is there another command that can help with my situation?

Thanks in advance!

It sounds like the 'data' database has references and links to the 'audit' database.

Try restoring the 'audit' database first, and then the 'data' database.

If I'm completely 'off base', let me know and we will try other tactics to help you.

|||I think you can use the REPLACE option of RESTORE to do this.|||

if I understand Properlly then try this

Go to Enterprise Manager,

select your server and right click your database,

then you see a option back up

just do backup

|||

Thanks everyone, but I sorted it myself.

The problem was that SQL didn't know which of the databases to restore so I had to use the 'PARTIAL, FILE = 1' extra commands in order to instruct SQL which database to restore and from what position.

Bacground Color of group

How do a change the alternate rows within a group.
ie i am grouping in a product type that also has a product numbers & value
on the same line. Since there is more than 1 product type there is multiple
rows within the group.
I have tried the formula iif(rownumber(nothing) Mod 2, "Red", "White")
But this doesnt seem to work.Although I do not know the answer, perhaps the problem is related to
rownumber(nothing)... I think the rownumber function applies to rows in the
data set... and I wonder if the GROUP lines do not get a rownumber with
(nothing) as the parameter... You might add the function to display in the
group field to check its value...
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Tango" <Tango@.discussions.microsoft.com> wrote in message
news:23069475-AA6E-42BA-9211-321A65D4C3CE@.microsoft.com...
> How do a change the alternate rows within a group.
> ie i am grouping in a product type that also has a product numbers & value
> on the same line. Since there is more than 1 product type there is
> multiple
> rows within the group.
> I have tried the formula iif(rownumber(nothing) Mod 2, "Red", "White")
> But this doesnt seem to work.|||Thanks Wayne,
I would have thought this to be a common problem...
"Wayne Snyder" wrote:
> Although I do not know the answer, perhaps the problem is related to
> rownumber(nothing)... I think the rownumber function applies to rows in the
> data set... and I wonder if the GROUP lines do not get a rownumber with
> (nothing) as the parameter... You might add the function to display in the
> group field to check its value...
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Tango" <Tango@.discussions.microsoft.com> wrote in message
> news:23069475-AA6E-42BA-9211-321A65D4C3CE@.microsoft.com...
> > How do a change the alternate rows within a group.
> >
> > ie i am grouping in a product type that also has a product numbers & value
> > on the same line. Since there is more than 1 product type there is
> > multiple
> > rows within the group.
> >
> > I have tried the formula iif(rownumber(nothing) Mod 2, "Red", "White")
> >
> > But this doesnt seem to work.
>
>

Saturday, February 25, 2012

Avoiding Extra page in printing

Hi,
I have finally worked my way through the process of creating a semi complex
report. It looks good. I like the product and have found it rich in neat
features.
However, it offers a page break option on table groups of either at the
start of the group or at the end of a group. The end of the group choice
displays properly in HTML however when I use the print icon on the print
toolbar, it prints an extra page because it breaks at the end of the last
group. Is there a way of turning off that final break at the end of print?
Thanks,
hughHi Hugh,
I understood it wil be a blank page for your
Please set PageBreakAtStart to be True and set PageBreakAtEnd to be False
to see whether it could resolve this.
If above does not work, would you please generate a sample rdl file with
AdventureWorks for me to reproduce it on my side?
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Michael,
Thanks it just worked as you said. I tried all different kind of
combinations. I am positive that I tried that one before and it only gave
me an extra page in the beginning instead of at the end. I must have had
something else wrong when I tried that combination.
Thank you very much.
hugh
"Michael Cheng [MSFT]" <v-mingqc@.online.microsoft.com> wrote in message
news:rFgfb314FHA.1144@.TK2MSFTNGXA01.phx.gbl...
> Hi Hugh,
> I understood it wil be a blank page for your
> Please set PageBreakAtStart to be True and set PageBreakAtEnd to be False
> to see whether it could resolve this.
> If above does not work, would you please generate a sample rdl file with
> AdventureWorks for me to reproduce it on my side?
>
> Sincerely yours,
> Michael Cheng
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> =====================================================> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>

Friday, February 24, 2012

Avoid Looping / Cursors. Help with Statement.

Hi Folks,
I have two tables, one of which I want to update from another.
Essentiall I have a table of orders and a product table. I want to
subtract the qty sold in the orders table from the QtyInStock column in
the Products table, for every line in an order.
But I dont really want to loop through each line in the order, either
in application or with a cursor as something is telling me there must
be a neater solution!
Example Orders Table.
OrderID ProductID Qty
1, 104, 2
1, 199, 1
2, 100, 3
3, 858, 1
ProductID, QtyInStock
104, 3
199, 1
etc ...
As you can see I want to be able to run a query against OrderID 1,
and it to reduce the QtyInStock column by the correct amount for
products 104 and 199 as an example.
Can this be done with one statement, or will I have to loop ?
Thanks in Advance.
Craig.Hi
CREATE TABLE #Test1
(
OrderID int,
ProductID int,
Qty int
)
INSERT INTO #Test1 VALUES (1,104,2)
INSERT INTO #Test1 VALUES (1,199,1)
INSERT INTO #Test1 VALUES (2,100,3)
INSERT INTO #Test1 VALUES (3,828,1)
CREATE TABLE #Test2
(
ProductID int,
QtyInStock int
)
INSERT INTO #Test2 VALUES (104,3)
INSERT INTO #Test2 VALUES (199,1)
UPDATE #Test1 SET Qty=(SELECT QtyInStock-Qty
FROM #Test2 T WHERE T.ProductID=#Test1.ProductID)
WHERE EXISTS (SELECT * FROM #Test2
T WHERE T.ProductID=#Test1.ProductID)
DROP TABLE #Test1,#Test2
<craig.parsons@.crawfos.com> wrote in message
news:1136476091.334221.282250@.g44g2000cwa.googlegroups.com...
> Hi Folks,
> I have two tables, one of which I want to update from another.
> Essentiall I have a table of orders and a product table. I want to
> subtract the qty sold in the orders table from the QtyInStock column in
> the Products table, for every line in an order.
> But I dont really want to loop through each line in the order, either
> in application or with a cursor as something is telling me there must
> be a neater solution!
> Example Orders Table.
> OrderID ProductID Qty
> 1, 104, 2
> 1, 199, 1
> 2, 100, 3
> 3, 858, 1
> ProductID, QtyInStock
> 104, 3
> 199, 1
> etc ...
> As you can see I want to be able to run a query against OrderID 1,
> and it to reduce the QtyInStock column by the correct amount for
> products 104 and 199 as an example.
> Can this be done with one statement, or will I have to loop ?
>
> Thanks in Advance.
>
> Craig.
>|||Uri,
I think Craig wants to update the quantity in stock
from the Product table, not the quantity in the Orders
table, which your query updates. He could use Jens's
solution, or one like this:
UPDATE #Products SET
QtyInStock = QtyInStock - (
SELECT SUM(O.Qty)
FROM #Orders AS O
WHERE O.ProductID = #Products.ProductID
)
WHERE EXISTS (
SELECT * FROM #Orders
WHERE #Orders.ProductID = #Products.ProductID
)
Steve Kass
Drew University
Uri Dimant wrote:

>Hi
>CREATE TABLE #Test1
>(
> OrderID int,
> ProductID int,
> Qty int
> )
>INSERT INTO #Test1 VALUES (1,104,2)
>INSERT INTO #Test1 VALUES (1,199,1)
>INSERT INTO #Test1 VALUES (2,100,3)
>INSERT INTO #Test1 VALUES (3,828,1)
>
>CREATE TABLE #Test2
>(
> ProductID int,
> QtyInStock int
> )
>INSERT INTO #Test2 VALUES (104,3)
>INSERT INTO #Test2 VALUES (199,1)
>
>UPDATE #Test1 SET Qty=(SELECT QtyInStock-Qty
>FROM #Test2 T WHERE T.ProductID=#Test1.ProductID)
>WHERE EXISTS (SELECT * FROM #Test2
>T WHERE T.ProductID=#Test1.ProductID)
>
>
>DROP TABLE #Test1,#Test2
>
>
><craig.parsons@.crawfos.com> wrote in message
>news:1136476091.334221.282250@.g44g2000cwa.googlegroups.com...
>
>
>|||craig.parsons@.crawfos.com wrote:
> Hi Folks,
> I have two tables, one of which I want to update from another.
> Essentiall I have a table of orders and a product table. I want to
> subtract the qty sold in the orders table from the QtyInStock column
> in the Products table, for every line in an order.
> But I dont really want to loop through each line in the order,
> either in application or with a cursor as something is telling me
> there must be a neater solution!
> Example Orders Table.
> OrderID ProductID Qty
> 1, 104, 2
> 1, 199, 1
> 2, 100, 3
> 3, 858, 1
> ProductID, QtyInStock
> 104, 3
> 199, 1
> etc ...
> As you can see I want to be able to run a query against OrderID 1,
> and it to reduce the QtyInStock column by the correct amount for
> products 104 and 199 as an example.
> Can this be done with one statement, or will I have to loop ?
>
Here is the ANSI version (I used the Sum function to guarantee only a single
result would be returned):
UPDATE Products
SET QtyInStock = QtyInStock -
(SELECT Sum(Qty) FROM Orders o
WHERE o.OrderID = 1 AND o.ProductID = Products.ProductID)
The T-SQL version:
UPDATE p
SET QtyInStock = QtyInStock - o.Qty
FROM Products p inner join (
SELECT ProductID,Sum(Qty) AS Qty FROM Orders
WHERE OrderID = 1 GROUP BY ProductID) o
ON o.ProductID = p.ProductID
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.