Blog Post

Finding Strings

,

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

A quick one today, just looking for strings. I wrote an article on this, so there’s more detail there, but here’s a bit of code you can look through and see what it does.

CREATE TABLE dbo.MyTable ( mystring VARCHAR(200) );

GO

INSERT dbo.MyTable

    ( mystring )

  VALUES

    ( ‘This is a 7’ )

  , ( ‘There is a 7 in this string’ )

  , ( ‘Why must 7 always be here’ )

  , ( ‘No 7s here. JK’ )

  , ( ‘My 7s here’ )

  , ( ‘An 7s here.’ )

  , ( ‘On 7s here.’ );

GO

SELECT

    ‘SetPosition’ = SUBSTRING(mystring, 4, 1)

  , ‘FindThe7’ = SUBSTRING(mystring, CHARINDEX(‘7’, mystring), 1)

  FROM

    dbo.MyTable AS mt;

DROP TABLE dbo.MyTable;

Filed under: Blog Tagged: SQLNewBlogger, syndicated, T-SQL

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating