我对程序一无所知,但我必须创建一个,所以我尝试了一个。但现在我收到了错误 - 请帮忙。
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Get_List_Docter_Detail_A]
@special varchar(MAX),
@city varchar(MAX),
@offset int,
@pageSet int,
@area varchar(MAX)
AS
Begin
declare @sql nvarchar(MAX);
set @sql = 'SELECT'+
'(SELECT Stuff('+
'(SELECT N"," + sp.specialization FROM DSpecialization_Master dsp'+
'LEFT JOIN Specialization_Master sp on sp.id = dsp.specialization'+
'WHERE dsp.profileid = pm.id and (dsp.specialization = (select id from Specialization_master where specialization='+@special+'))'+
'FOR XML PATH(""),TYPE)'+
'.value("text()[1]","nvarchar(max)"),1,1,N"")) as drspec,'+
'pm.id as profileid,'+
'pm.loginid as loginid,'+
'dam.clinicname,'+
'dam.area,'+
'dam.address,'+
'dam.pincode,'+
'dam.id as addressid,'+
'dam.feecharge as feecharge,'+
'pm.fname,'+
'pm.lname,'+
'pm.email,'+
'pm.mobile,'+
'pm.phone,'+
'pm.gender,'+
'pm.dob,'+
'pm.totexp,'+
'pm.imagepath,'+
'pm.languages,'+
'pm.statement,'+
'pm.createdby,'+
'convert(nvarchar, pm.createdon, 103) as createddate,'+
'convert(nvarchar, pm.createdon, 108) as createdtime,'+
'pm.hsbit,'+
'overall_count = COUNT(*) OVER(),'+
'(SELECT Stuff('+
'(SELECT N"," + education FROM DEducation_Master WHERE profileid = pm.id'+
'FOR XML PATH(""),TYPE)'+
'.value("text()[1]","nvarchar(max)"),1,1,N"")) as dredu'+
'FROM Profile_Master pm '+
'LEFT JOIN DAddress_Master dam on dam.profileid = pm.id '+
'WHERE '+
'dam.city='+@city;
if @area!=''
set @sql+=' and dam.area in('+@area+') and';
set @sql+=' pm.id IN (SELECT profileid FROM DSpecialization_Master WHERE specialization = (select id from Specialization_master where specialization='+@special+')) ORDER BY dam.city OFFSET '+@offset+' ROWS FETCH NEXT '+@pageSet+' ROWS ONLY';
EXECUTE sp_executesql @sql
END
我收到此错误。
Msg 245,Level 16,State 1,Procedure Get_List_Docter_Detail_A,Line 61
转换nvarchar值时转换失败' SELECT(SELECT Stuff((SELECT N"," + sp.specialization FROM DSpecialization_Master dspLEFT JOIN Specialization_Master sp on sp.id = dsp.specializationWHERE dsp.profileid = pm .id和(dsp.specialization =(从Specialization_master中选择id,其中specialization = Dentist))FOR XML PATH(""),TYPE).value(" text()[1]&# 34;," nvarchar(max)"),1,1,N""))作为drspec,pm.id作为profileid,pm.loginid作为loginid,dam.clinicname, dam.area,dam.address,dam.pincode,dam.id as addressid,dam.feecharge as feecharge,pm.fname,pm.lname,pm.email,pm.mobile,pm.phone,pm.gender,pm。 dob,pm.totexp,pm.imagepath,pm.languages,pm.statement,pm.createdby,convert(nvarchar,pm.createdon,103)as createddate,convert(nvarchar,pm.createdon,108)as createdtime,pm。 hsbit,overall_count = COUNT(*)OVER(),(SELECT Stuff((SELECT N"," + education FROM DEducation_Master WHERE profileid = pm.idFOR XML PATH(""), TYPE)。价值("文本()[1]&#34 ;," nvarchar(max)"),1,1,N""))作为dreduFROM Profile_Master pm LEFT JOIN DAddress_Master dam on dam.profileid = pm.id WHERE dam.city =(Adajan)中的surat和dam.area以及'数据类型int。
我做错了什么?请纠正我。
答案 0 :(得分:0)
尝试用双单配额替换双配额
替换此行
'(SELECT N"," + sp.specialization
用
'(SELECT N'','' + sp.specialization