Join SQL Server tables on a like statement

后端 未结 4 2133
清酒与你
清酒与你 2021-02-19 18:37

I am hoping this isn\'t a repeat. I\'ve checked the searches and I can\'t seem to find a clear answer to this.

I have a table that has it\'s primary key set to be a

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-19 19:17

    Do you know that the = is always there and always is a UNIQUEIDENTIFIER. Then you can do this:

    WHERE CAST(SUBSTRING(URL, CHARINDEX('=',URL)+1,LEN(URL)) AS UNIQUEIDENTIFIER)=StateID
    

    EDIT

    As part of the comment you can also so it with a JOIN. Like this:

    select 
       u.* 
    from 
       urltable
    join statetable s 
       on CAST(SUBSTRING(URL, CHARINDEX('=',URL)+1,LEN(URL)) AS UNIQUEIDENTIFIER)=StateID
    

提交回复
热议问题