Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE ##table1 (
- Id INT
- , text1 VARCHAR(50)
- , text2 VARCHAR(50)
- );
- INSERT INTO ##table1 (
- Id
- , text1
- , text2
- )
- VALUES
- (1, 'This is a string to test against another string', 'Another string to concat')
- , (2, 'This is a second string', '')
- , (3, 'And a third string', '')
- , (4, 'Some random string', '')
- , (5, 'The istring containis the istring is iniside', '')
- CREATE TABLE ##table2 (
- Id INT
- , text1 VARCHAR(50)
- );
- INSERT INTO ##table2 (
- Id
- , text1
- )
- VALUES
- (1, 'abc')
- , (2, 'acc')
- , (3, 'adc')
- , (4, 'adac')
- , (5, 'adcc')
- , (6, 'cac')
- , (7, 'daz')
- -- + operator
- SELECT
- text1 + text2 AS textConcatenation1
- FROM ##table1
- WHERE Id = 1
- -- += operator
- DECLARE @t1 VARCHAR(50) = '';
- SET @t1 += 'Hello';
- SET @t1 += ' World';
- SELECT @t1;
- -- % operator, starts with
- SELECT Id, text1
- FROM ##table1
- WHERE text1 LIKE('this%')
- -- % operator, contains
- SELECT Id, text1
- FROM ##table1
- WHERE text1 LIKE('%is%')
- -- % operator, ends with
- SELECT Id, text1
- FROM ##table1
- WHERE text1 LIKE('%string')
- -- % operator
- SELECT *
- FROM ##table2
- WHERE text1 LIKE('a%c')
- -- _ operator
- SELECT *
- FROM ##table2
- WHERE text1 LIKE('a_c')
- -- [] operator
- SELECT *
- FROM ##table2
- WHERE text1 LIKE('a[cd]c')
- -- [] operator with a range
- SELECT *
- FROM ##table2
- WHERE text1 LIKE('a[b-d]c')
- -- [^] operator
- SELECT *
- FROM ##table2
- WHERE text1 LIKE('a[^cd]c')
- DROP TABLE ##table1
- DROP TABLE ##table2
Advertisement
Add Comment
Please, Sign In to add comment