another sql insert

want to create spreadsheet9
very similiar to spreadsheet8 which works


spreadsheet9 includes
countrycode table
which has values countrycode, shipcountry, countrynumber

is the insert for spreadsheet9 correct
create table spreadsheet8(
[dateordered] [datetime] NULL,
[blank1] [varchar](50) NULL,
[orderid] [int] NULL,
[internalsku] [varchar](20) NULL,
[quantity] [int] NULL,
[blank2] [varchar](50) NULL,
[deliveryservicecode][int] NULL,
[blank3] [varchar](50) NULL,
[companyname] [varchar](100) NULL,
[shipaddress1] [varchar](100) NULL,
[shipaddress2] [varchar](100) NULL,
[shipaddress3] [varchar](100) NULL,
[blank4] [varchar](50) NULL,
[shipzip] [varchar](15) NULL,
[blank5] [varchar](50) NULL,
[country] [varchar] (90) NULL,
[contactname] [varchar](100) NULL,
[shipphone1] [varchar](50) NULL
)

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





create table spreadsheet9(
[blank1] [varchar](50) NULL,
[orderid] [int] NULL,
[internalsku] [varchar](20) NULL,
[quantity] [int] NULL,
[blank2] [varchar](50) NULL,
[countrynumber][int] NULL,
[blank3] [varchar](50) NULL,
[companyname] [varchar](100) NULL,
[shipaddress1] [varchar](100) NULL,
[shipaddress2] [varchar](100) NULL,
[shipaddress3] [varchar](100) NULL,
[blank4] [varchar](50) NULL,
[shipzip] [varchar](15) NULL,
[blank5] [varchar](50) NULL,
[countrycode] [varchar] (90) NULL,
[contactname] [varchar](100) NULL,
[shipphone1] [varchar](50) NULL
)
INSERT INTO spreadsheet9 ([orderid], [internalsku], [quantity], [deliveryservicecode], 
      [companyname], [shipaddress1], [shipaddress2],[shipaddress3], [shipzip], [country],[contactname], [shipphone1]) 
SELECT o.OrderID,p.internalsku,i.Quantity,c.countrynumber, RTRIM ( LTRIM( o.shipfirstname + ' ' + o.shiplastname ) ) ,o.shipaddress1,o.shipaddress2,o.shipcity, o.shipzip,c.countrycode, 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
		inner join countrycode c on c.shipcountry = o.shipcountry 
where i.orderid = @x

Open in new window

LVL 1
rgb192Asked:
Who is Participating?
 
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
assuming that [shipaddress3] = ShipCity , that seems perfect
0
 
igni7eConnect With a Mentor Commented:
yes it looks good, why do u ask? why not run it?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.