473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Changing Data Format On Select

Hey all,
I have a basic table that looks something like this.

CREATE TABLE MyTable
(
ID INT IDENTITY PRIMARY KEY,
Company_ID INT NOT NULL,
Round VARCHAR(50) NOT NULL,
Details VARCHAR(250) NOT NULL
)

It has a few rows of data that look like this:

Identity Company_ID Round Details
--------------------------------------------
1 5 A Blah, blah.
2 5 B Generic data, blah blah.
3 5 WERT More generic blah blah.
Now what i'm trying to do during my select statement is select all the rows
that belong to company_id 5 but if any of the rows round value contains the
text "WERT" convert that text into just a "--" for presentation purposes,
but still select that row. I can't seem to figure out how i would transform
the text in the select statement? My immediate thought was substring /
replace but i would need to combine it with an if else statement which i've
no idea how to make work in a select (sub-query maybe?) statement. Is this
possible? Perhaps i'm stuck iterating through the returned data within the
client application before presenting?

Any help, as always, would be greatly appreciated.

Muhd
Jul 20 '05 #1
5 2342
Muhd,

SELECT ID, Company_ID,
[Round] = CASE [Round] WHEN 'WERT' THEN '--' ELSE [Round] END,
Details
FROM MyTable
WHERE Company_ID = 5

-Andy
"Muhd" <ea*@joes.com> wrote in message news:7MZ4d.91084$%S.84951@pd7tw2no...
Hey all,
I have a basic table that looks something like this.

CREATE TABLE MyTable
(
ID INT IDENTITY PRIMARY KEY,
Company_ID INT NOT NULL,
Round VARCHAR(50) NOT NULL,
Details VARCHAR(250) NOT NULL
)

It has a few rows of data that look like this:

Identity Company_ID Round Details
--------------------------------------------
1 5 A Blah, blah.
2 5 B Generic data, blah blah.
3 5 WERT More generic blah blah.
Now what i'm trying to do during my select statement is select all the
rows that belong to company_id 5 but if any of the rows round value
contains the text "WERT" convert that text into just a "--" for
presentation purposes, but still select that row. I can't seem to figure
out how i would transform the text in the select statement? My immediate
thought was substring / replace but i would need to combine it with an if
else statement which i've no idea how to make work in a select (sub-query
maybe?) statement. Is this possible? Perhaps i'm stuck iterating through
the returned data within the client application before presenting?

Any help, as always, would be greatly appreciated.

Muhd

Jul 20 '05 #2
Although Andy has shown you how you can accomplish the task using
Transact-SQL, formatting data for presentation purposes is generally best
handled on the client side, IMHO. Most programming languages provide a
number of methods to format data.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Muhd" <ea*@joes.com> wrote in message news:7MZ4d.91084$%S.84951@pd7tw2no...
Hey all,
I have a basic table that looks something like this.

CREATE TABLE MyTable
(
ID INT IDENTITY PRIMARY KEY,
Company_ID INT NOT NULL,
Round VARCHAR(50) NOT NULL,
Details VARCHAR(250) NOT NULL
)

It has a few rows of data that look like this:

Identity Company_ID Round Details
--------------------------------------------
1 5 A Blah, blah.
2 5 B Generic data, blah blah.
3 5 WERT More generic blah blah.
Now what i'm trying to do during my select statement is select all the
rows that belong to company_id 5 but if any of the rows round value
contains the text "WERT" convert that text into just a "--" for
presentation purposes, but still select that row. I can't seem to figure
out how i would transform the text in the select statement? My immediate
thought was substring / replace but i would need to combine it with an if
else statement which i've no idea how to make work in a select (sub-query
maybe?) statement. Is this possible? Perhaps i'm stuck iterating through
the returned data within the client application before presenting?

Any help, as always, would be greatly appreciated.

Muhd

Jul 20 '05 #3
While the front end is a very good place for presentation or value decoding
....
having a record transformation in the database allows the logic to be
centralized and recorded somewhere.

what if in addition to WERT you need to ignore SPAM, just add a row to the
table. no front end changes needed.

create a decoder table and join to that returning --

create view round_decoder
(
Round VARCHAR(50) NOT NULL,
DisplayName VARCHAR(50) NOT NULL
)

insert into round_decoder ( 'WERT' , '--' )

SELECT
Identity,
Company_ID ,
IsNull( d.DisplayName , x.Round ) as Round ,
Details
FROM MyTable x
LEFT JOIN round_decoder d on x.Round = d.Round

you can query this decoder table for drop down lists or other data
selection / presentation stuff in the front end.
i would recommend a reusable object that get's this data and does the
decoding in the front end.

"Dan Guzman" <gu******@nospam-online.sbcglobal.net> wrote in message
news:pf*****************@newssvr12.news.prodigy.co m...
Although Andy has shown you how you can accomplish the task using
Transact-SQL, formatting data for presentation purposes is generally best
handled on the client side, IMHO. Most programming languages provide a
number of methods to format data.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Muhd" <ea*@joes.com> wrote in message

news:7MZ4d.91084$%S.84951@pd7tw2no...
Hey all,
I have a basic table that looks something like this.

CREATE TABLE MyTable
(
ID INT IDENTITY PRIMARY KEY,
Company_ID INT NOT NULL,
Round VARCHAR(50) NOT NULL,
Details VARCHAR(250) NOT NULL
)

It has a few rows of data that look like this:

Identity Company_ID Round Details
--------------------------------------------
1 5 A Blah, blah.
2 5 B Generic data, blah blah. 3 5 WERT More generic blah blah.
Now what i'm trying to do during my select statement is select all the
rows that belong to company_id 5 but if any of the rows round value
contains the text "WERT" convert that text into just a "--" for
presentation purposes, but still select that row. I can't seem to figure out how i would transform the text in the select statement? My immediate thought was substring / replace but i would need to combine it with an if else statement which i've no idea how to make work in a select (sub-query maybe?) statement. Is this possible? Perhaps i'm stuck iterating through the returned data within the client application before presenting?

Any help, as always, would be greatly appreciated.

Muhd


Jul 20 '05 #4
Thanks for that, David... Great idea!

-Andy

"David Rawheiser" <ra*******@hotmail.com> wrote in message
news:4C********************@bgtnsc04-news.ops.worldnet.att.net...
While the front end is a very good place for presentation or value
decoding
...
having a record transformation in the database allows the logic to be
centralized and recorded somewhere.

what if in addition to WERT you need to ignore SPAM, just add a row to the
table. no front end changes needed.

create a decoder table and join to that returning --

create view round_decoder
(
Round VARCHAR(50) NOT NULL,
DisplayName VARCHAR(50) NOT NULL
)

insert into round_decoder ( 'WERT' , '--' )

SELECT
Identity,
Company_ID ,
IsNull( d.DisplayName , x.Round ) as Round ,
Details
FROM MyTable x
LEFT JOIN round_decoder d on x.Round = d.Round

you can query this decoder table for drop down lists or other data
selection / presentation stuff in the front end.
i would recommend a reusable object that get's this data and does the
decoding in the front end.

"Dan Guzman" <gu******@nospam-online.sbcglobal.net> wrote in message
news:pf*****************@newssvr12.news.prodigy.co m...
Although Andy has shown you how you can accomplish the task using
Transact-SQL, formatting data for presentation purposes is generally best
handled on the client side, IMHO. Most programming languages provide a
number of methods to format data.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Muhd" <ea*@joes.com> wrote in message

news:7MZ4d.91084$%S.84951@pd7tw2no...
> Hey all,
> I have a basic table that looks something like this.
>
> CREATE TABLE MyTable
> (
> ID INT IDENTITY PRIMARY KEY,
> Company_ID INT NOT NULL,
> Round VARCHAR(50) NOT NULL,
> Details VARCHAR(250) NOT NULL
> )
>
> It has a few rows of data that look like this:
>
> Identity Company_ID Round Details
> --------------------------------------------
> 1 5 A Blah, blah.
> 2 5 B Generic data, blah blah. > 3 5 WERT More generic blah blah.
>
>
> Now what i'm trying to do during my select statement is select all the
> rows that belong to company_id 5 but if any of the rows round value
> contains the text "WERT" convert that text into just a "--" for
> presentation purposes, but still select that row. I can't seem to figure > out how i would transform the text in the select statement? My immediate > thought was substring / replace but i would need to combine it with an if > else statement which i've no idea how to make work in a select (sub-query > maybe?) statement. Is this possible? Perhaps i'm stuck iterating through > the returned data within the client application before presenting?
>
> Any help, as always, would be greatly appreciated.
>
> Muhd
>



Jul 20 '05 #5
Thanks all !!!

I've decided to keep the presentation logic on the presentation tier but i
did rig up a "decoder" table to give it a try and it worked for me really
well. It's something i'll have to add to my toolkit of tricks in case i
need it in the future.

Thanks,
Muhd.

"Andy Williams" <f_u_b_a_r_1_1_1_9@y_a_h_o_o_._c_o_m> wrote in message
news:c1******************@newssvr33.news.prodigy.c om...
Thanks for that, David... Great idea!

-Andy

"David Rawheiser" <ra*******@hotmail.com> wrote in message
news:4C********************@bgtnsc04-news.ops.worldnet.att.net...
While the front end is a very good place for presentation or value
decoding
...
having a record transformation in the database allows the logic to be
centralized and recorded somewhere.

what if in addition to WERT you need to ignore SPAM, just add a row to
the
table. no front end changes needed.

create a decoder table and join to that returning --

create view round_decoder
(
Round VARCHAR(50) NOT NULL,
DisplayName VARCHAR(50) NOT NULL
)

insert into round_decoder ( 'WERT' , '--' )

SELECT
Identity,
Company_ID ,
IsNull( d.DisplayName , x.Round ) as Round ,
Details
FROM MyTable x
LEFT JOIN round_decoder d on x.Round = d.Round

you can query this decoder table for drop down lists or other data
selection / presentation stuff in the front end.
i would recommend a reusable object that get's this data and does the
decoding in the front end.

"Dan Guzman" <gu******@nospam-online.sbcglobal.net> wrote in message
news:pf*****************@newssvr12.news.prodigy.co m...
Although Andy has shown you how you can accomplish the task using
Transact-SQL, formatting data for presentation purposes is generally
best
handled on the client side, IMHO. Most programming languages provide a
number of methods to format data.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Muhd" <ea*@joes.com> wrote in message

news:7MZ4d.91084$%S.84951@pd7tw2no...
> Hey all,
> I have a basic table that looks something like this.
>
> CREATE TABLE MyTable
> (
> ID INT IDENTITY PRIMARY KEY,
> Company_ID INT NOT NULL,
> Round VARCHAR(50) NOT NULL,
> Details VARCHAR(250) NOT NULL
> )
>
> It has a few rows of data that look like this:
>
> Identity Company_ID Round Details
> --------------------------------------------
> 1 5 A Blah, blah.
> 2 5 B Generic data, blah

blah.
> 3 5 WERT More generic blah blah.
>
>
> Now what i'm trying to do during my select statement is select all the
> rows that belong to company_id 5 but if any of the rows round value
> contains the text "WERT" convert that text into just a "--" for
> presentation purposes, but still select that row. I can't seem to

figure
> out how i would transform the text in the select statement? My

immediate
> thought was substring / replace but i would need to combine it with an

if
> else statement which i've no idea how to make work in a select

(sub-query
> maybe?) statement. Is this possible? Perhaps i'm stuck iterating

through
> the returned data within the client application before presenting?
>
> Any help, as always, would be greatly appreciated.
>
> Muhd
>



Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lawrence | last post by:
I had some code that worked fine for several weeks, and then yesterday it stopped working. I'm not sure what I did. Nor can I make out why it isn't working. I'm running a query that should return 3...
2
by: Paolo Pignatelli | last post by:
I am trying to get an output/file like this (below) in an XML file (MyXmlFile.xml) (which I will use for a slide show) -- <gallery timer="3" order="sequential" fadetime="2" looping="yes"...
10
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
32
by: deko | last post by:
I have a popup form with a textbox that is bound to a memo field. I've been warned about memo fields so I'm wondering if I should use this code. Is there any risk with changing the form's...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
15
by: cephal0n | last post by:
I have a technical Date problem that's really difficult for me, I have a "custom made" Date format MM.DD.YY this is actually extracted from SAP and theirs no other format option offered such as...
6
by: and1 | last post by:
hello .. hmm currently i'm working on vba in excel, apparently i use ADO to extract a table data from access to excel and it works fine. the problem is when i use the extracted data to create a chart...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.