SQL field save value [1, 2, 3, 4, 5] complex method, add SQL functions to favorites

Source: Internet
Author: User

Set ANSI_NULLS ON <br/> set QUOTED_IDENTIFIER ON <br/> go <br/> alter function [dbo]. [fun_Str] (@ SourceSql varchar (8000), @ StrSeprate varchar (10) <br/> RETURNS @ temp TABLE (a varchar (100 )) <br/> BEGIN <br/> DECLARE @ I int <br/> SET @ SourceSql = RTRIM (@ SourceSql )) <br/> SET @ I = charindex (@ StrSeprate, @ SourceSql) <br/> WHILE @ I> = 1 <br/> BEGIN <br/> INSERT @ temp values (left (@ SourceSql, @ i-1 )) </p> <p> SET @ SourceSql = SUBSTRING (@ SourceSql, @ I + 1, LEN (@ SourceSql)-@ I) </p> <p> SET @ I = CHARINDEX (@ StrSeprate, @ SourceSql) <br/> END <br/> IF @ SourceSql <> '/' <br/> INSERT @ temp values (@ SourceSql) <br/> RETURN <br/> END <br/> 

The above is the SQL method,

 

Select B. *,. weburl from UsedCar_SubSiteList a, UsedCar_FriendLink B <br/> where. id in (<br/> SELECT a FROM dbo. fun_Str (. subSiteIds <br/>, ',') <br/>) 

Table Structure Relationship

SubSiteList (id, weburl)

FriendLink (id, name, subIds)

Description: The format of the subIds saved field is: 1, 2, 3, 4, 5...; subIds Save the id value in SubSiteList;

 

 

 

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.