2016-08-23 43 views
1
CREATE procedure [dbo].[usp_insertleavedetails]     
@Emp_id int ,     
@Rec_Name varchar(50) ,     
@CompanyName varchar(30) ,    
@Month_Year varchar(9),   
@Task varchar(20) ,  
@RemainingDaysofLeave varchar(2),    
@NoOfDaysLeavTakn varchar(12) ,     
@NoOfAvailblLeav varchar ,     
@LossofPay varchar(2) ,    
@LeaveTakndates varchar(200),    
@TtlLeavTakn varchar(12)       

AS       
BEGIN           
Insert into tbl_Leavetbl(Emp_id,Rec_Name,CompanyName,Month_Year,Task,RemainingDaysofLeave,NoOfDaysLeavTakn ,NoOfAvailblLeav ,LossofPay ,LeaveTakndates,TtlLeavTakn)     
Values(@Emp_id ,@Rec_Name,@CompanyName,@Month_Year,@Task,@RemainingDaysofLeave,@NoOfDaysLeavTakn,@NoOfAvailblLeav,@LossofPay,(SELECT LEFT(Leavetakndates,CASE WHEN CHARINDEX(',',Leavetakndates)>0 THEN LEN(Leavetakndates)-1 ELSE LEN(Leavetakndates) END) FROM tbl_Leavetbl),@TtlLeavTakn)     
END 

這是插入過程我用,在「LeaveTakndates」本場我將與comma.I分隔日期值需要刪除最後一個逗號。雖然插入值,我需要從日期刪除最後一個逗號,並在插入過程保存

+0

提供樣本數據 – Mani

回答

0

不知道樣本數據,它很難猜測你的邏輯,你可以做到這一點,除去最後一個逗號

left((SELECT LEFT(Leavetakndates,CASE WHEN CHARINDEX(',',Leavetakndates)>0 THEN LEN(Leavetakndates)-1 ELSE LEN(Leavetakndates) END),len((SELECT LEFT(Leavetakndates,CASE WHEN CHARINDEX(',',Leavetakndates)>0 THEN LEN(Leavetakndates)-1 ELSE LEN(Leavetakndates) END))-1) 
下面

是一些例子給你一些想法..

declare @string varchar(max)='a,b,c,' 
select left(@string,len(@string)-1) 

輸出: a,b,c

+0

08/09/2016,08/17/2016,樣本數據將如下所示編輯在插入sp中使用它 – hari