Hi, all! I've got the following script:
Insert into Manual.dbo.nsc
select SSN,
FName,
LName ,
STUFF((select ',' + n1.SchoolCode from Manual.dbo.New_Clr n1 where
n1.SSN=n2.SSN for XML path('')),1,1,'') as school_code,
STUFF((select ',' + n1.FrmDate from Manual.dbo.New_Clr n1 where
n1.SSN=n2.SSN for XML path('')),1,1,'') as FromDate,
STUFF((select ',' + n1.ToDate from Manual.dbo.New_Clr n1 where
n1.SSN=n2.SSN for XML path('')),1,1,'') as ToDate
from Manual.dbo.New_Clr n2 group by ssn, fname, lname
What I'm needing is (I think!) a CASE statement for each of the STUFF to do what I need it to do.
For example, the second STUFF would need to be something like this:
CASE when n1.FrmDate < 1 then n1.FrmDate=' '
else
STUFF((select ',' + n1.SchoolCode from Manual.dbo.New_Clr n1 where
n1.SSN=n2.SSN for XML path('')),1,1,'') as school_code
So, basically, if the field in the STUFF statement is less than 1, it needs to return 8 blank spaces, but if the field is greater than 1, it needs to run that STUFF statement to be inserted into the table.