我有两种类型的数据库,如
DB1:
度:
资格:
DB2:
UG_LIST:
名称
ID
PGLIST:
名称
ID
DoctorateList:
名称
ID
此处 Degrees 表是单一的。所有学位如Ug,Pg,doctorate都存储在名为 Degrees 的单个表中。但是在数据库-2中,每个项目都是作为单独的表创建的。所以我必须将这三个表值存储到 Qualifications 表中。
我使用了连接。但我无法为此创建选择查询。
SELECT top(50) 'INSERT INTO CandidateQualifications(candidateId,DegreeId,specialization) VALUES('+
Cast(c.CandidateID as varchar(50))+',''' +
Isnull(Cast(u.Id as varchar(50)),'NULL') Or cast(p.Id as varchar(50)) or cast(d.Id as varchar(50))+','+
IsNull(''''+c.ugspecification+'''', 'NULL')+')'
FROM candidatedetails as c
right join UG_List As u ON c.qualification=u.UGName
right join PG_List As p ON c.qualification=u.pgname
right join Docorate_List As d ON c.qualification=u.docorate
请告诉我怎么做?我使用Or运算符,但它不接受。
有什么想法吗?
答案 0 :(得分:2)
替换:
Isnull(Cast(u.Id as varchar(50)),'NULL') Or cast(p.Id as varchar(50)) or cast(d.Id as varchar(50))
使用:
Cast(Coalesce(u.Id,p.Id,d.Id)as varchar(50))
我希望联接为left
SELECT top(50) 'INSERT INTO CandidateQualifications(candidateId,DegreeId,specialization) VALUES('+
Cast(c.CandidateID as varchar(50))+',''' +
Cast(Coalesce(u.Id,p.Id,d.Id)as varchar(50))+','+
IsNull(''''+c.ugspecification+'''', 'NULL')+')'
FROM candidatedetails as c
LEFT join UG_List As u ON c.qualification=u.UGName
LEFT join PG_List As p ON c.qualification=p.pgname
LEFT join Docorate_List As d ON c.qualification=d.docorate