Hello,Basically I am trying to extract a username from a column containing a line of text. Not each field for that column will contain a username but when it does it will always be the last word and preceded with "by". Example = "This is some text by BOBBY".This new functionality will be added on to a current SELECT statement. Seen below. The rows I get back were fine but now I don't want rows entered by the administrator I just want rows from all other users. The username I don't want to be found will be stored in a config table and not hardcoded. TSQL follows:CURRENT SELECT STATEMENTSELECT * FROM LOG_TABLE WHERE DATE_TIME >= '2009-01-08 04:10:20.0000000'AND SERVER_ID = 1AND CODE IN(Select CODES_TO_CHECK FROM CODE_TABLE)
LOG_TABLE definitionCREATE TABLE LOG_TABLE( [SERVER_ID] [numeric](3, 0) NOT NULL, [NAME] [nvarchar](80) NULL, [DATE_TIME] [datetime2](7) NOT NULL, [LOG_NUM] [numeric](4, 0) NOT NULL, [TEXT] [nvarchar](255) NULL, [CODE] [numeric](3, 0) NULL, CONSTRAINT [PK_LOG_TABLE] PRIMARY KEY CLUSTERED ( [SERVER_ID] ASC, [DATE_TIME] ASC, [LOG_NUM] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GO
CODE_TABLE definitionCREATE TABLE CODE_TABLE( [CODES_TO_CHECK] [numeric](3, 0) NOT NULL, CONSTRAINT [PK_CODE_TABLE] PRIMARY KEY CLUSTERED ( [MESSAGE_CODE_TO_BE_CHECKED] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GO
Config table definition (containing username)CREATE TABLE CONFIG_TABLE( [SERVER_ID] [numeric](3, 0) NOT NULL, [USERNAME_TO_IGNORE] [nvarchar](50) NULL, CONSTRAINT [PK_CONFIG_TABLE] PRIMARY KEY CLUSTERED ( [SERVER_ID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GO
I assume I need to use something like substring,regex in a function or SP?Just looking for a general idea on how to tackle this efficiently.Thanks