Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-08-22
3
Medium Priority
?
451 Views
Last Modified: 2012-05-10
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!
0
Comment
Question by:jeremyll
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 2000 total points
ID: 33497507
Try this
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%'

Open in new window

0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33497525
Sorry correction.
You really should look at changing the TEXT columns to VARCHAR(MAX) ...
;with tmp as (
	select xaoFormID, xaoControlName, xaoClassID, xaoType, xaoProperties, xaoCodeVC = CONVERT(varchar(max), xaoCode)
	from FormDefinitions
	-- WHERE CLAUSE HERE
)
select xaoFormID, xaoControlName, xaoClassID, xaoType, xaoProperties, first500ofX= SUBSTRING(xaoCodeVC,
	PATINDEX('%Determine part ID for Product version and installation - for base price lookup%', xaoCodeVC), 500)
from tmp
where xaoCodeVC like '%Determine part ID for Product version and installation - for base price lookup%'

Open in new window

0
 

Author Closing Comment

by:jeremyll
ID: 33497600
TOO GOOD!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question