-2

Below is my database fields.

Select FilterType,FilterValue from filter;

FilterType                          FilterValue
Fabric,Coller,Occasion,Sleeve,Fit   Cotton,Rounded Neck,,Long Sleeve,Regular Fit
Fabric,Coller,Occasion,Sleeve,Fit   Cotton,Square Neck,Formal,Long Sleeve,Slim Fit
Fabric,Coller,Occasion,Sleeve,Fit   Linen,Square Neck,Formal,Long Sleeve,Regular Fit
Fabric,Coller,Occasion,Sleeve,Fit   ,,,,
Fabric,Coller,Occasion,Sleeve,Fit   ,,,,
Fabric,Coller,Occasion,Sleeve,Fit   ,Square Neck,,,

I want convert all filter type with its value.

Means i want Output like this:

Fabric = Cotton,Linen

Coller = Rounded Neck,Square Neck

Occasion = Formal

Sleeve = Long Sleeve

Fit = Regular Fit,Slim Fit

So how to solve this

VIPUL PARMAR
  • 280
  • 2
  • 4
  • 29
  • Please read the [how to ask](http://stackoverflow.com/help/how-to-ask) help primer. – Paul Jul 06 '15 at 09:43
  • Also, which language are you using; C# or one of the Classic ASP languages (JScript/VBScript)? – Paul Jul 06 '15 at 09:44
  • @Paul FilterType and FilterValue is my Database fields – VIPUL PARMAR Jul 06 '15 at 09:48
  • 3
    Why is your database set up like this? Your `FilterType`s should be separated, for instance: (unique id, filtertype, filtervalue) 1, "Fabric", "Cotton"; 2, "Fabric", "Linen"; 3, "Collar", Rounded Neck"; 4, "Collar", "Square Neck" ... etc, Perhaps you should read up first on [normalisation](https://en.wikipedia.org/wiki/Database_normalization) before continuing down the path you're on. – Paul Jul 06 '15 at 09:57
  • All the data are unique for product now i want to display it for filtration that's why i want to separate it. – VIPUL PARMAR Jul 06 '15 at 10:05
  • You should either have separated fields for each of the values you've specified (i.e. a `fabric` field, a `collar` field, an `occasion` field, a `sleeve` field etc), or, most likely a better solution would be to have a properties table associated to your product (or whatever) table so that you could attach 1 or more properties to the product that you're trying to filter. Design is everything. – Paul Jul 06 '15 at 13:44

1 Answers1

0

I am assuming OP already has a database storing data as comma separated array.

Although I believe OP is better off changing the database structure, I will based on whatever information OP has provided.

If you are using postgres as database, there is an UNNEST function which allows you to use sql queries on data stored as a comma separated list instead of row wise records.

If you are using MYSQL, the solution is not so simple. This might help. UNNEST function in MYSQL like POSTGRESQL

Community
  • 1
  • 1