﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / T-SQL (SS2K5)  / SQL Query by splitting the encoded text. / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 08:29:37 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: SQL Query by splitting the encoded text.</title><link>http://www.sqlservercentral.com/Forums/Topic765065-338-1.aspx</link><description>[quote][b]steven (8/4/2009)[/b][hr]Thanks it worked for me, but I don't know how to mark your reply as Answer. can you tell me?[/quote]I don't think you can in this forum, well, just saying it will help people who are looking for the same answer.Thanks for the feedback Steven, have a nice day,</description><pubDate>Tue, 04 Aug 2009 13:59:15 GMT</pubDate><dc:creator>J-F Bergeron</dc:creator></item><item><title>RE: SQL Query by splitting the encoded text.</title><link>http://www.sqlservercentral.com/Forums/Topic765065-338-1.aspx</link><description>Thanks it worked for me, but I don't know how to mark your reply as Answer. can you tell me?</description><pubDate>Tue, 04 Aug 2009 13:53:48 GMT</pubDate><dc:creator>steven-733381</dc:creator></item><item><title>RE: SQL Query by splitting the encoded text.</title><link>http://www.sqlservercentral.com/Forums/Topic765065-338-1.aspx</link><description>[quote][b]steven (8/4/2009)[/b][hr]Hi,I have a situation where I have bunch of 7-digit Encoded text in database like 0304182, now here First two characters represent Product i.e. 03Next two character represent Class i.e. 04 andLast thress characters represent SubClass i.e. 182Now I want to fill thress dropdowns (i.e. Product, Class, SubClass) with the distinct value from the database, where Subclass will populate on Class selection and Class will populate on Product selection.So can anyone suggest me the SQL query to get it to work ? Hope you understand the situation. I am using SQL server 2005.[/quote]Hi Steven,I built this query for you, check it out, see if it does what you are looking for.[code]USE tempdbGODROP TABLE ProductCREATE TABLE Product (  ID             INT   IDENTITY ( 1 , 1 ),  EncodedProduct VARCHAR(7))INSERT INTO Product           (EncodedProduct)SELECT '0101001'UNION ALLSELECT '0201001'UNION ALLSELECT '0301001'UNION ALLSELECT '0301002'UNION ALLSELECT '0102001'UNION ALLSELECT '0202001'UNION ALLSELECT '0302001'UNION ALLSELECT '0303001'UNION ALLSELECT '0401001'UNION ALLSELECT '0504001'UNION ALLSELECT '0101010'UNION ALLSELECT '0102010'UNION ALLSELECT '0103010'UNION ALLSELECT '0203010'--This fills your PrdCode comboSelect distinct PrdCode from (SELECT substring(EncodedProduct,1,2) AS PrdCode,	   Substring(EncodedProduct,3,2) AS PrdClass,	   Substring(EncodedProduct,5,3) AS PrdSubClassFROM   Product) as PrdGO--This fills your PrdClass combo based on the PrdCode selection (@PrdCode)Declare @PrdCode varchar(2)set @PrdCode = '01'select distinct PrdClass from (SELECT substring(EncodedProduct,1,2) AS PrdCode,	   Substring(EncodedProduct,3,2) AS PrdClass,	   Substring(EncodedProduct,5,3) AS PrdSubClassFROM   Product) as Prdwhere PrdCode = @PrdCodeGODeclare @PrdCode varchar(2),		@PrdClass varchar(2)SET @PrdCode = '03'SET @PrdClass = '01'select distinct PrdSubClass from (SELECT substring(EncodedProduct,1,2) AS PrdCode,	   Substring(EncodedProduct,3,2) AS PrdClass,	   Substring(EncodedProduct,5,3) AS PrdSubClassFROM   Product) as Prdwhere PrdCode = @PrdCodeAND PrdClass = @PrdClass[/code]</description><pubDate>Tue, 04 Aug 2009 13:32:29 GMT</pubDate><dc:creator>J-F Bergeron</dc:creator></item><item><title>SQL Query by splitting the encoded text.</title><link>http://www.sqlservercentral.com/Forums/Topic765065-338-1.aspx</link><description>Hi,I have a situation where I have bunch of 7-digit Encoded text in database like 0304182, now here First two characters represent Product i.e. 03Next two character represent Class i.e. 04 andLast thress characters represent SubClass i.e. 182Now I want to fill thress dropdowns (i.e. Product, Class, SubClass) with the distinct value from the database, where Subclass will populate on Class selection and Class will populate on Product selection.So can anyone suggest me the SQL query to get it to work ? Hope you understand the situation. I am using SQL server 2005.</description><pubDate>Tue, 04 Aug 2009 12:22:58 GMT</pubDate><dc:creator>steven-733381</dc:creator></item></channel></rss>