sql2008 converts rows to strings, converts strings to rows

Source: Internet
Author: User

--Convert line to string select Stuff ([select top], ' + QQ from DL_QQ where uiid=1 order by Tim Desc FOR XML Path (') '), 1, 1, ')--======= ======================================--Description: Converting a string to a table/* Example: SELECT * FROM [F_split] (' spu0987*5//spu0988*5/ Spu0989*5 ', '/')--convert the table to a string declare @S NVARCHAR (max) SELECT @s=isnull (@s+ ', ', ') +[col] from [F_split] (' spu0987*5// Spu0988*5/spu0989*5 ', '/') PRINT @s*/--=============================================create function [dbo]. [Strtotab] (@c varchar (max), @split varchar (2))  Returns @t table (col nvarchar (255))  as      begin while           (CHARINDEX (@split, @c) <>0)          begin            Insert   @t (col)   Values   (substring (@c,1,charindex (@split, @c)-1)            set   @c   =   Stuff (@ C,1,charindex (@split, @c), ')          end        Insert   @t (col)   values   (@c)        return      End

  

sql2008 converts rows to strings, converts strings to rows

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.