Question : SQL Select: display only the first 500 characters from the start of the line where code like '%'Determine part ID for ...%'

Thanks CyberKiwi! I have a similar question…

The table FormDefinitions is as follows:

(<xaoFormID, char(75),>
 ,<xaoControlName, char(70),>
,<xaoClassID, char(35),>
,<xaoType, numeric(1,0),>
,<xaoProperties, text,>
,<xaoCode, text,>):

xaoCode contains over 900 lines of VBScript code. So doing a basic SQL select isn't very helpful when I only want to view only parts of the VBScript code.

I would like to get SQL Server 2008 to display the xaoCode values from the start of the line…

where like ‘%'Determine part ID for Product version and installation - for base price lookup%’

and onwards for the first 500 characters

Thanks!

Answer : SQL Select: display only the first 500 characters from the start of the line where code like '%'Determine part ID for ...%'

Try this
1:
2:
3:
4:
5:
with tmp as (select *, xaoCodeVC = CONVERT(varchar(max), xaoCode) from FormDefinitions)
select *, first500ofX= SUBSTRING(xaoCodeVC,
	PATINDEX('%Determine part ID for Product version and installation - for base price lookup%', xaoCodeVC), 500)
from tmp
where xaoCode like '%Determine part ID for Product version and installation - for base price lookup%'
Random Solutions  
 
programming4us programming4us