Solved

Need Help Splitting Strings, evaluating numerical parts and concatenating results

Posted on 2013-05-29
2
223 Views
Last Modified: 2013-05-29
Hi,

I need to create a view based upon a SQL table that contains 2 string fields (Job, Serial) i.e. one job contains many serials in this table.

The Serial string consists of 4 alpha then 5 numeric. (e.g. ABDC12345)

The resulting View needs to have the following fields (Job, Start Serial, End Serial) for each Job number

Where Start Serial consists of the 4 alpha & the lowest 5 numeric for the given Job
Where End Serial consists of the 4 alpha & the highest 5 numeric for the given job

Any preceding zeros in the 5 numeric portion of the Serial string need to be maintained when the numeric portion is joined back to the resulting Start Serial & End Serial strings)

i.e. ABCD00001 not ABDC1 (resulting string must always be 9 chars in length)
0
Comment
Question by:Japsterex
2 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 39204929
SELECT
    Job, MIN(Serial) AS Start_Serial, MAX(Serial) AS End_Serial
FROM dbo.tablename
GROUP BY Job
0
 

Author Comment

by:Japsterex
ID: 39204972
brilliant

didn't realize min and max would work with strings, I've been over complicating this somewhat.

Excellent
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Results to Excel File 18 76
SQL Server Trigger 8 37
SQL Server Error while building a sql query using concatenate statements 3 20
SQL Syntax 6 29
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

756 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