473,395 Members | 1,689 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,395 software developers and data experts.

How to convert then combine field values

I have a StudentsTable which has 3 fields to describe which class a student belongs to.

The first is session, in the db it is stored as 1 or 2.
afternoon,morning (values 1, 2)

Language, also stored as 1, 2.
English, Chinese (values 1, 2)

Class number which has values K1,K2,3,4,G...etc. This list is long and changes from time to time.

For example a student who goes to class morning,english,K2 is known as class MEK2 (values 2,1,K2 in his record in the database)

I want to know how many different classes there are in the school.

This much of the sql I know...

step 1
First convert from numeric values to alpha
Expand|Select|Wrap|Line Numbers
  1. CASE WHEN Session=1 THEN 'E' ELSE 'C' END
  2. CASE WHEN Language=1 THEN 'A' ELSE 'M' END
step 2
Combine the three parts into one alpha value eg MEK2, AC4, etc

step 3
Do steps 1,2 for all of the student records but take only the distinct values. (I can then display this list in a dropdown box.)

Can anyone help me with the sql to extract the information?

I think the sql might be something like this but obviously it does not work.

Expand|Select|Wrap|Line Numbers
  1. select concat(sess,lang,classnum) as clas from studentstbl inner join  where studentstbl.sess, studentstbl.lang in
  2. (select case when session=1 then 'a' else 'm' end as sess, case when language=1 then 'm' else 'c' end as lang from studentstbl)
thanks
Jun 3 '15 #1
0 1478

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: epascual | last post by:
I need to combine fields values: FirstName and Last Name to Full Name in the same table. I like to put the value on the full name after completing entry for the full name. Thanks for the help. ...
5
by: mehere | last post by:
Please excuse me if I am posting in wrong NG. Can someone explain how I can use javascript (I am assuming this is the best way to do it) to add two field values together. I.e. field 1 plus field...
2
by: Learner | last post by:
Hello, I am trying to store the data entered in a webform in the database. I have few Int and one SmallDateTime filed in my table in SQL Server 2005 database. I have made a storedproc to store the...
5
by: sklett | last post by:
I'm not real experienced with asp.net so this may be obvious. I've got a situation where some of my client side javascript is causing my posted form's controls to lose their values. In other...
9
by: manjubarkavi | last post by:
how to convert a MsAccess database table which contains formated string values in the field (like ###99@<) to simple plain text format.
1
by: dean.brunne | last post by:
Hi, In the code below I scroll throught the firldnames of a query ignoring the first three then converting the remaining fields to first: the fieldnames as a record in a field called Product...
9
ADezii
by: ADezii | last post by:
There are basically 4 Methods that you can use to access the values of Fields in Recordsets. For the purposes of this demonstration, I'll be using a Table called tblEmployees, a Field named , and a...
1
by: AccessHunter | last post by:
Please Help.... I have a query with 2 tables, LegalFile and Cases. LegalFile has the field CaseID(Number Field) and Cases has CaseNbr(Text Field). I am trying to find entries that are in...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.