Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

If then in sql string

I am trying to write an sql statement and I know Im wrong below.

Essentially, if tblRegistration.Overage = 3, then AttendanceGrid Set X = 'X'
and  if tblRegistration.Overage is not 3, then AttendanceGrid Set X = ' '

How do I write that correctly below
Update AttendanceGrid Set X = 'X'
FROM tblRegistration INNER JOIN AttendanceGrid  on tblRegistration.id=AttendanceGrid.id 
and tblRegistration.Overage = 3
Else
Update AttendanceGrid Set X = ''
FROM tblRegistration INNER JOIN AttendanceGrid  on tblRegistration.id=AttendanceGrid.id 
and tblRegistration.Overage < 3

Open in new window

0
al4629740
Asked:
al4629740
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
Update AttendanceGrid Set X = case when tblRegistration.Overage = 3 THEN  'X' else '' end
FROM tblRegistration INNER JOIN AttendanceGrid  on tblRegistration.id=AttendanceGrid.id
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now