zoukankan      html  css  js  c++  java
  • sql left join 字符串

    要实现join字符串

    select * FROM table1 as t1
    right join (select '1,2,3,4,5'  as t) as tt on t1.Id=tt.t

    则需要分割字符串为数组,以下为实现的分割字符串函数split

     split函数及使用示例: 


    select * FROM table1 as t1
    right join (select * from split('1,3,5',',')) as tt on t1.Id=tt.F1

    split函数:

    /*
    获取字符串数组的 Table www.cnblogs.com/xqhppt/p/4377757.html
    */

    if exists (select 1 from sysobjects where id = object_id('split' ))
    drop Function split
    go
    CREATE function split(
    @SourceSql varchar (max),
    @StrSeprate varchar (10)
    )
    returns @temp table( F1 varchar (100))
    as
    begin
    declare @i int
    set @SourceSql =rtrim( ltrim(@SourceSql ))
    set @i =charindex( @StrSeprate,@SourceSql )
    while @i >=1
    begin
    insert @temp values(left( @SourceSql,@i -1))
    set @SourceSql =substring( @SourceSql,@i +1, len(@SourceSql )-@i)
    set @i =charindex( @StrSeprate,@SourceSql )
    end

    if @SourceSql <>''
    insert @temp values( @SourceSql)

    return
    end
    GO

    FromUrl:www.cnblogs.com/xuejianxiyang/p/7025929.html

  • 相关阅读:
    自考新教材-p209
    自考新教材-p205
    自考新教材-p200
    自考新教材-p197
    Java IO (5)
    Java IO (1)
    Java IO (2)
    Java IO (3)
    通过源码学Java基础:InputStream、OutputStream、FileInputStream和FileOutputStream
    Spring入门(1)-第一个Spring项目
  • 原文地址:https://www.cnblogs.com/xuejianxiyang/p/7025929.html
Copyright © 2011-2022 走看看