A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi,@Bone_12
Welcome to Microsoft T-SQL Q&A Forum!
First, when completing this code , you need to explain the data in sys_Text . Your code direction will explain that there are only two kinds of data in this field: sys and spaces .
If this is the case , you can try to run the following code.
;with cte as
(
select name,ref,a.date,
max(case when lap = '1' and syst = '1' then sys_boolean else 0 end) as isnew,
case when (lap = '2' and syst = '1') then sys_Text else '' end as category
from [cf].[dbo].[cust] as a
left join [cf].[dbo].[emp] as b on a.id = b.id
group by name,max(case when lap = '1' and syst = '1' then sys_boolean else 0 end),a.date,category
)
select name,ref,a.date,isnew, distinct(Replace(category,' ','sys')) from cte
Just a reminder: if this doesn't do what you want, please attach your DDL statement so we can test it.
Best regards,
Bert Zhou
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.