2015-08-24 87 views
0

我在一列中分割了一個名稱值以獲取在另一列中提供的名字和姓氏。在某人姓名的前面或開始處引用(「)。我如何刪除該報價?如何在將SQL字符串輸入列之前或之後刪除引號(「)

我已經嘗試過實際操作,但它在@fname和@lname的設置命令處啓動了錯誤。

DECLARE @fname VARCHAR(100) 
    DECLARE @lname VARCHAR(100) 
    DECLARE @recnum as INT 
    DECLARE @i as int 
    SELECT @recnum = count(*) FROM dbo.medcor_weeklywire 
    SET @i = 1 
    WHILE @i <[email protected] 
    BEGIN 

    SELECT @fname = LTRIM(jw_employee_fname) where [sysid] = @i 
    SELECT @lname = LTRIM(jw_employee_lname) where [sysid] = @i 
    SET @fname = SELECT REPLACE(@fname,'"','') 
    SET @lname = SELECT REPLACE(@lname,'"','') 
    update [medcor_weeklywire] 
    SET [jw_employee_fname] = @fname, [jw_employee_lname] = @lname 

    END 

回答

1

無論是走SELECT出第二個聲明:

SET @fname = REPLACE(@fname,'"','') 

或只是將它們合併到一個SELECT

SELECT @fname = REPLACE(LTRIM(jw_employee_fname),'"','') where [sysid] = @i 
+0

是的,我認爲這是它。這需要一些時間來循環。邁克爾你知道另一種方式? – Michael

0

好第一關邁克爾SELECT語句是錯誤的。其次你白癡LOL

DECLARE @fname VARCHAR(100) 
    DECLARE @lname VARCHAR(100) 
    DECLARE @recnum as INT 
    DECLARE @i as int 
    SELECT @recnum = count(*) FROM dbo.medcor_weeklywire 
    SET @i = 1 
    WHILE @i <[email protected] 
    BEGIN 

    SELECT @fname = LTRIM(jw_employee_fname) from medcor_weeklywire where [sysid] = @i 
    SELECT @lname = LTRIM(jw_employee_lname) from medcor_weeklywire where [sysid] = @i 

    update [medcor_weeklywire] 

    SET [jw_employee_fname] = REPLACE([jw_employee_fname], '"',''), [jw_employee_lname] = REPLACE([jw_employee_lname],'"','') 
    END 

我建議你從頭開始,不使用循環它花的時間過長...

相關問題