Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

sql adding fields to table

this works

but i want to
set @x = orderid


declare @x int 
set @x = 1287003

while @x < 1287009 
BEGIN
INSERT INTO spreadsheet8 ([dateordered], [orderid], [internalsku], [quantity], [deliveryservicecode], 
      [companyname], [shipaddress1], [shipaddress2],[shipaddress3], [shipzip], [country],[contactname], [shipphone1]) 
SELECT o.dateordered,o.OrderID,p.internalsku,i.Quantity,12, RTRIM ( LTRIM( o.shipfirstname + ' ' + o.shiplastname ) ) ,o.shipaddress1,o.shipaddress2,o.shipcity, o.shipzip,o.shipcountry, RTRIM ( LTRIM( o.shipfirstname + ' ' + o.shiplastname ) ) ,shipphone1 
from  
        products p 
        inner join orderitems i on  p.productid = i.productid 
        inner join orders o on o.orderid = i.orderid 
where i.orderid = @x
SET @x = @x +1 
END
select * from spreadsheet8 order by orderid desc

Open in new window

0
rgb192
Asked:
rgb192
  • 4
  • 4
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
Seems bit confusing , is this something like this


declare @x int
SELECT @x = OrderID
FROM Orders
Where < SomeCondition > 
0
 
rgb192Author Commented:
will this be the orderid from table
spreadsheet8
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
>will this be the orderid from table spreadsheet8
so i think you are looking for the orderid from the 'speadsheet' table after the insert statement, In that case i dont think you have to assign it, because that orderid will lways be the value of  @x  " where i.orderid = @x " 
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
rgb192Author Commented:
i have to do the query once a day as i get orders


i dont want to delete the table
and insert ALL the orders


i want to resume every day from yesterday where i left off

how does orderid know the value from yesterday

select top orderid from spreadsheet8
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
select @x = max(orderid)  from spreadsheet8
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
select top 1 @x = orderid from spreadsheet8  order by orderid desc
0
 
rgb192Author Commented:
select top 1 @x = orderid from spreadsheet8  order by orderid desc
works
but

i would like 1 to this number

because the current orderid repeats in the table
0
 
rgb192Author Commented:
thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now