Avatar of Jiggens
Jiggens

asked on 

SQL INSERTING INTO TABLE

How do i make this query work, so that where contacts.first_name='Accounts' it inserts a 'Y' into contactlist.list_flag.  Currently the FLAG is null when i run this query.


SELECT     contacts.id, contacts.address_id, contacts.address_name, contacts.date_created, contacts.first_name, contacts.last_name, contacts.title,
                      contactlist.list_flag
FROM         P21.dbo.contacts AS contacts LEFT OUTER JOIN
                      P21.dbo.contactlist AS contactlist ON contacts.id = contactlist.contact_id
WHERE     (contacts.first_name = 'ACCOUNTS')
ORDER BY contacts.address_id

When i run an update

UPDATE    P21.dbo.contactlist
SET              list_flag = 'Y'
FROM         P21.dbo.contacts AS contacts LEFT OUTER JOIN
                      P21.dbo.contactlist ON contacts.id = P21.dbo.contactlist.contact_id
WHERE     (contacts.first_name = 'ACCOUNTS')

i get 4 records updated, i want to insert the value 'Y' into all of the contact_id  that have a list_flag value of NULL or blank.   Can anyone help me?


ConactsResults.png
Oracle DatabaseMicrosoft SQL Server 2005SQL

Avatar of undefined
Last Comment
folderol

8/22/2022 - Mon