I am new to writing case statements in SQL server. What I'm trying to do is if an account has more than 1 customer name ID, I want the phone number to be null otherwise, I want to pull the phone_number.
The case statement is highlighted in RED:
DECLARE @order_ID nvarchar(10),@other_info_2 varchar(100),@inet_event_description varchar(100),@section_name varchar(10),@add_usr varchar(100),@cust_name_id varchar (100),@name nvarchar(100),@num_seats nvarchar(100),@class_name varchar (100),@strSubject varchar(100), @strBody varchar(4000), @type tinyint, @bitmap char (6),@cursor varchar(25),@live_order_id nvarchar(25),@email_addr varchar(25),@order_num nvarchar(50),@order_line_item nvarchar(10), @order_line_item_seq nvarchar(10),@acct_id varchar(10),@event_date nvarchar(25),@event_time nvarchar(25)
DECLARE UnVerifiedCursor CURSOR FOR
SELECT v_returned_inventory.order_id,v_live_inventory.inet_event_description,v_live_inventory.event_date,v_live_inventory.event_time, v_live_inventory.section_name,
v_returned_inventory.add_usr, v_live_inventory.num_seats, v_returned_inventory.acct_id, v_live_inventory.class_name,
AT_trans_for_emailTrigger.email_addr, AT_trans_for_emailTrigger.cust_name_id, premclub.name_first + ' ' + premclub.name_last AS name CASE phone when count(cust_name_id > 1) then @phone = null else @phone = v_cust_phone.phone_number_formatted
FROM v_returned_inventory INNER JOIN
v_live_inventory ON LEFT(v_returned_inventory.event_name, 6) = LEFT(v_live_inventory.event_name, 6) AND
v_returned_inventory.orderNumber = v_live_inventory.other_info_1 INNER JOIN
AT_trans_for_emailTrigger ON v_returned_inventory.order_id = AT_trans_for_emailTrigger.order_id LEFT OUTER JOIN
OPENQUERY(premclub, 'select name_first, name_last, cust_name_id from dba.v_cust_name') AS premclub ON
AT_trans_for_emailTrigger.cust_name_id = premclub.cust_name_id
GROUP BY v_returned_inventory.acct_id, v_returned_inventory.order_id, v_live_inventory.section_name, v_live_inventory.inet_event_description,
v_live_inventory.num_seats, v_returned_inventory.add_usr, v_live_inventory.class_name,v_live_inventory.event_date,v_live_inventory.event_time,
AT_trans_for_emailTrigger.email_addr, AT_trans_for_emailTrigger.cust_name_id, premclub.name_first + ' ' + premclub.name_last
The case statement is highlighted in RED:
DECLARE @order_ID nvarchar(10),@other_info_2 varchar(100),@inet_event_description varchar(100),@section_name varchar(10),@add_usr varchar(100),@cust_name_id varchar (100),@name nvarchar(100),@num_seats nvarchar(100),@class_name varchar (100),@strSubject varchar(100), @strBody varchar(4000), @type tinyint, @bitmap char (6),@cursor varchar(25),@live_order_id nvarchar(25),@email_addr varchar(25),@order_num nvarchar(50),@order_line_item nvarchar(10), @order_line_item_seq nvarchar(10),@acct_id varchar(10),@event_date nvarchar(25),@event_time nvarchar(25)
DECLARE UnVerifiedCursor CURSOR FOR
SELECT v_returned_inventory.order_id,v_live_inventory.inet_event_description,v_live_inventory.event_date,v_live_inventory.event_time, v_live_inventory.section_name,
v_returned_inventory.add_usr, v_live_inventory.num_seats, v_returned_inventory.acct_id, v_live_inventory.class_name,
AT_trans_for_emailTrigger.email_addr, AT_trans_for_emailTrigger.cust_name_id, premclub.name_first + ' ' + premclub.name_last AS name CASE phone when count(cust_name_id > 1) then @phone = null else @phone = v_cust_phone.phone_number_formatted
FROM v_returned_inventory INNER JOIN
v_live_inventory ON LEFT(v_returned_inventory.event_name, 6) = LEFT(v_live_inventory.event_name, 6) AND
v_returned_inventory.orderNumber = v_live_inventory.other_info_1 INNER JOIN
AT_trans_for_emailTrigger ON v_returned_inventory.order_id = AT_trans_for_emailTrigger.order_id LEFT OUTER JOIN
OPENQUERY(premclub, 'select name_first, name_last, cust_name_id from dba.v_cust_name') AS premclub ON
AT_trans_for_emailTrigger.cust_name_id = premclub.cust_name_id
GROUP BY v_returned_inventory.acct_id, v_returned_inventory.order_id, v_live_inventory.section_name, v_live_inventory.inet_event_description,
v_live_inventory.num_seats, v_returned_inventory.add_usr, v_live_inventory.class_name,v_live_inventory.event_date,v_live_inventory.event_time,
AT_trans_for_emailTrigger.email_addr, AT_trans_for_emailTrigger.cust_name_id, premclub.name_first + ' ' + premclub.name_last