SQL parse string added to temp table in SQL stored procedure in parameter input

Source: Internet
Author: User
Tags parse string

SQL parse string added to temporary table SQL stored procedure in parameter input workaround

Adding string parsing to a staging table

SELECT * into #临时表 from dbo. Func_splitonecolumntabel (' 001,gf ', ', ')

SELECT * FROM table where ID in (SELECT ID from temp table)

Create function [dbo]. [Func_splitonecolumntabel]
(@str nvarchar (max), @split varchar (10))
Returns @t Table (KeyColumn varchar (200))
As
Begin
While Len (@str) >0
Begin
If CHARINDEX (@split, @str) >0
Begin
INSERT into @t (keycolumn) VALUES (left (@str, CHARINDEX (@split, @str)-1))
Set @str =right (@str, Len (@str)-charindex (@split, @str))
End
Else
Begin
INSERT into @t (keycolumn) VALUES (@str)
Set @str = ' '
End
End
Return
End

How to use

SELECT * FROM dbo. Func_splitonecolumntabel (' 001,gf ', ', ')

Results

KeyColumn
001
Gf

SQL parse string added to temp table in SQL stored procedure in parameter input

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.