Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Insert index into Temporary Table
/* ** Create Tables */ CREATE TABLE customers ( customer_id INT NOT NULL, customer_name VARCHAR(100), customer_invoice_rate DECIMAL(3,2), customer_vat_rate DECIMAL(3,2), CONSTRAINT PK_customers PRIMARY KEY (customer_id) ); CREATE TABLE customer_invoices ( invoice_id INT NOT NULL, invoice_customer_id INT NOT NULL, invoice_amount DECIMAL(19,4), CONSTRAINT PK_customer_invoices PRIMARY KEY (invoice_id) ); /* ** Sample Data */ INSERT INTO customers (customer_id, customer_name, customer_invoice_rate, customer_vat_rate) VALUES( 1, 'Customer 1', 1, 0.20), ( 2, 'Customer 2', 0.90, 0.20), ( 3, 'Customer 3', 0.80, 0.00), -- Not charged VAT ( 4, 'Customer 4', 1, 0.20), ( 5, 'Customer 5', 1, 0.00) -- Not charged VAT ; INSERT INTO customer_invoices (invoice_id, invoice_customer_id, invoice_amount) VALUES( 1, 1, 100), ( 2, 2, 200), ( 3, 3, 100), ( 4, 4, 100), ( 5, 5, 100), ( 6, 2, 100), ( 7, 3, 100), ( 8, 4, 100) ; DECLARE @CustomerID INT = 1; /* ** Apply discount to invoice in code */ SELECT IDENTITY(int,1,1) As KEY_ID, * INTO #Temp FROM Customers ; Select * FROM #Temp ; GO
run
|
edit
|
history
|
help
0
Segundo
20181CSE0041
a
How to find 2nd highest salary
mywall
performance on update using subquery versus correlated update
New_1
28-02
Running Total
megha