i am new in sql and i want that , i have a table Customer
in which i added a new field Region now i want to do some
alteration in SQL . I want to get all records Customerand check on each
// This check will perfome for every customer let suppose we have our first customer
if currentcustomer.Country = 'US'
{
UPDATE currentcustomer SET currentcustomer.Region=currentcustomer.id
}
else
{
UPDATE currentcustomer SET currentcustomer.Region=currentcustomer.ZIP
}
this is what i want to do but i dont know that how to do this over all customers and how to do this in sql . Please Help me Thanks!!!
Avoid looping within SQL – it is not designed for looping.
Try to formulate your requirements in set based terminology (I need to update all customers who’s country is
USto have regionAAand all others to regionZZ).Update:
Seeing your edit, and assuming it is sensible (compatible data types and meaningful data):