Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Select and set to variable
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2014
Application:
Web
Divers
Thread ID:
01616353
Message ID:
01616377
Vues:
38
For now ignore in this sample code the column 'rec_id'
declare @Used decimal (12,2)
set @Used = 7
create table #invstock (inv_code char(20), qty_left decimal(10,2), inven_pk int, unit_price decimal (12,2), rec_id char(1))
go
insert into #invstock (inv_code, qty_left, inven_pk, unit_price, rec_id) values 
	('ABC', 15, 1, 1.93, '1')
insert into #invstock (inv_code, qty_left, inven_pk, unit_price, rec_id) values 
	('ABC', 4, 2, 1.93, '1')
insert into #invstock (inv_code, qty_left, inven_pk, unit_price, rec_id) values 
	('ABC', 7, 3, 1.93, '1')
insert into #invstock (inv_code, qty_left, inven_pk, unit_price, rec_id) values 
	('ABC', 8, 4, 1.93, '1')
I need to create a SQL Update that will change the value of each record column QTY_LEFT subtracting the value of @Used.
That is, if the value of @Used is 7, only the first row will change the value of QTY_LEFT to 8. But if the value of @Used in 20, then the first row will have the value of QTY_LEFT as 0, the second row will be 0, and the 3rd one will have QTY_LEFT as 6.

This is one small part of the overall SQL I am trying to create but I need to break it down so that I can understand it.

>Can you provide more details?
>
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform