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
441 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
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
TOO GOOD!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now