DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

retrieve values

This is a discussion on retrieve values within the SQL Development forums, part of the Databases category; Hi, I have a field called Options The values in the field are stored like this Easy to access, Somewhat ...

Go Back   DeveloperBarn Forums > Databases > SQL Development

  #1  
Old June 19th, 2008, 12:19 PM
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 462
Rep Power: 2
todd2006 is an unknown quantity at this point
Default retrieve values

Hi,

I have a field called Options

The values in the field are stored like this

Easy to access, Somewhat easy, Very hard

How can i find the count of "somewhat easy" in this field

todd
Reply With Quote
  #2  
Old June 19th, 2008, 01:12 PM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Real name: Jason
Location: Washington, D.C.
Posts: 1,964
Blog Entries: 8
Rep Power: 15
jmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud of
Default

What database are you using?
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding

Reply With Quote
  #3  
Old June 19th, 2008, 01:13 PM
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 462
Rep Power: 2
todd2006 is an unknown quantity at this point
Default

sql server
Reply With Quote
  #4  
Old June 19th, 2008, 01:33 PM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Real name: Jason
Location: Washington, D.C.
Posts: 1,964
Blog Entries: 8
Rep Power: 15
jmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud ofjmurrayhead has much to be proud of
Default

Okay, I think it can be done if you use a stored procedure with some TSQL. However, I encourage you to rethink your database design. This does not follow database normalization rules.

Instead of a comma delimited field, create another table that will create a relationship with the values you are storing and the record.

For example, let's say you have the following tables:

Users:
userid username password

UserGroups:
groupid groupname permissions

To allow a user to be a member of multiple groups you would have the following table:

UsersInGroups:
ugpid userid groupid

Then you can more easily and efficiently do any type of query against the data with the help of joins to get the desired result. I suggest you do the same with your database.
Reply With Quote
  #5  
Old June 19th, 2008, 01:44 PM
Wolffy's Avatar
Wolfmaster
 
Join Date: Mar 2008
Real name: Wolff
Location: Peoria, IL
Posts: 779
Blog Entries: 1
Rep Power: 9
Wolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to behold
Default

I take it to mean that the field can be one of 3 values, Easy, Sorta, Hard (or whatever). However, I wouldn't do it this way either, but add the other table with 3 records and a PK of 1,2,3. Then in the parent table, the field either has a value of 1, 2 or 3. So the count becomes:
Code:
SELECT COUNT(1) FROM daTable where daField = 2
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
  #6  
Old June 19th, 2008, 01:46 PM
Wolffy's Avatar
Wolfmaster
 
Join Date: Mar 2008
Real name: Wolff
Location: Peoria, IL
Posts: 779
Blog Entries: 1
Rep Power: 9
Wolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to beholdWolffy is a splendid one to behold
Default

OK, on third read, I've changed my mind. One of the basic rules of relational databases is the a filed can have only 1 value. So you should create a table for storing your three options -- same advice as in my last post.
Reply With Quote
Reply

  DeveloperBarn Forums > Databases > SQL Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Store Calculated Values (Updating Fields) sbenj69 Access Database Samples 9 January 12th, 2009 11:49 AM
Data is Null. This method or property cannot be called on Null values. Shem .Net Development 8 June 17th, 2008 09:39 AM


All times are GMT -4. The time now is 01:49 AM.


Copyright ©2008-2010, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.2