INSERT INTO Tbl_Basicinfo(Employer_Id,Lname,Fname,UserName,Userpass,Location_Id,cc2,CC3,cc4,cc5,Dohire,Job_Status,ssn,Import_Emp_No,[Benefit_Terminate], [Show_Age], [Change_IP], [IsNewHired])
SELECT M.Employer_Id,M.LASTNAME,M.FIRSTNAME,UPPER(LEFT(ISNULL(M.FIRSTNAME,'A'),1)+''+LEFT(ISNULL(M.LASTNAME,'C'),1))+CONVERT(VARCHAR,MaxImportEENumber+ROWNUM) [UserName],RIGHT(NEWID(),10) [UserPass],ISNULL(M.Location_Id,0)[Location_Id],M.Level2code,M.Level3code,M.LEVEL4Code,M.LEVEL5Code,M.DATEOFHIRE,
1 [JobStatus],SSN,M.MaxImportEENumber+ROWNUM [ImportEmpNo],0 [Benefit_Terminate], 0[Show_Age],M.ChangeIP,1 [IsNewHired] from(
SELECT ROW_NUMBER() OVER(ORDER BY [FIRSTNAME]) AS ROWNUM,* FROM
(
SELECT DISTINCT @Employer_Id [Employer_Id],PR.LASTNAME,PR.FIRSTNAME,(SELECT MAX(CAST(ISNULL(Employee_Id,0) as BIGINT)) from Tbl_Basicinfo) [MaxImportEENumber],
(SELECT TOP 1 Location_Id from Tbl_Location where Location_Code=PR.LEVEL1CODE and Employer_Id=@Employer_Id and Location like '%'+PR.LEVEL1DESCRIPTION+'%') [Location_Id],
(SELECT TOp 1 LEVEL2Code from Tbl_PPACA_Import where ssn=PR.SSN and EmployerId=PR.EmployerId) LEVEL2Code,
(SELECT TOp 1 LEVEL3Code from Tbl_PPACA_Import where ssn=PR.SSN and EmployerId=PR.EmployerId) LEVEL3Code,
(SELECT TOp 1 LEVEL4Code from Tbl_PPACA_Import where ssn=PR.SSN and EmployerId=PR.EmployerId) LEVEL4Code,
(SELECT TOp 1 LEVEL5Code from Tbl_PPACA_Import where ssn=PR.SSN and EmployerId=PR.EmployerId) LEVEL5Code,
(SELECT MIN(DATEOFHIRE) from Tbl_PPACA_Import where ssn=PR.SSN and EmployerId=PR.EmployerId) DATEOFHIRE,1 Job_Status,PR.SSN,PR.ChangeIP
from Tbl_PPACA_Import PR
LEFT OUTER JOIN Tbl_Basicinfo L ON L.ssn=PR.SSN and L.Employer_Id=PR.EmployerId
WHERE PR.EmployerId=@Employer_Id and L.SSN is null and ISNULL(PR.SSN,'') not like '' AND ISNUMERIC(PR.SSN)=1
and ISNULL(PR.PPE,DATEOFHIRE) =(SELECT MAX(ISNULL(PPE,DATEOFHIRE)) FROM Tbl_PPACA_Import I WHERE I.SSN=PR.SSN AND I.EmployerId=PR.EmployerId )
) V
) M;
注意:有人可以帮助我,我从上面的查询中收到此错误:
错误515:无法将值NULL插入列'UserName',表'ppacahelper.dbo.Tbl_Basicinfo';列不允许空值。 INSERT失败。行:131 spImportPPACAREPORT
任何帮助都将受到高度赞赏
答案 0 :(得分:2)
我认为您需要将ISNULL添加到您为用户名值连接的所有列:
checkIt(data){
var countriesByName = d3.nest()
.key(function(d) { return d.Country_Names; })
.entries(data);
console.log(countriesByName)
function makePie(){
var chart = c3.generate({
data: {
columns: [
function(m) {
var obj = [];
for (var i in m) {
obj.push('Road ' + m.countriesByName[i].key.values.Food and tobacco);
}
return obj;
}
],
type : 'donut'
}
});
}
makePie();
};
d3.json("https://gist.githubusercontent.com/heenaI/cbbc5c5f49994f174376/raw/82cd19eff7db367193cf8ce00144a40ea8d140ac/data.json", checkIt);
答案 1 :(得分:1)
这个表达式似乎返回NULL:
UPPER(LEFT(ISNULL(M.FIRSTNAME,'A'),1)+''
+LEFT(ISNULL(M.LASTNAME,'C'),1))
+CONVERT(VARCHAR,MaxImportEENumber+ROWNUM)
由于ISNULL
上的M.FIRSTNAME
,第一部分不会为NULL
由于ISNULL
上的M.LASTNAME
,第二部分不会为NULL
所以它必须是第三部分......
MaxImportEENumber
或ROWNUM
必须为NULL ...
请检查一下......
您可以通过编写
轻松定义默认值 注意:您可能希望将CONVERT(VARCHAR
更改为CONVERT(VARCHAR(XY)
。没有指定长度,你就不会得到你期望的......
+ISNULL(CONVERT(VARCHAR(100),MaxImportEENumber+ROWNUM),'YourDefaultValue')