Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
[1] I have created one data report(student report).
[2] which shows records of students as per the fields selected from various combos situated at form2 for that I wrote a record set (bunch of sql statements) fired on command_click and it works well.....
[3] Now I am having fields like: FIRST_NAME,MIDDLE_NAME,LAST_NAME in database table
[4] For that I have to take one RptTextBox as FULLNAME which is not included in table but I have to concatenate these 3 fields to view FULLNAME......
[5] I don't know how to do so.......

VB
Private Sub CmdReport_Click()
Dim STR As String
    STR = Search1
   sql = "SELECT  A.ROLLNO,A.FIRST_NAME,A.MIDDLE_NAME,A.LAST_NAME,A.ADDRESS,A.GRADE,B.DIV,A.BLOOD_GROUP,C.HOUSE,A.DATE_OF_BIRTH,A.TRANSPORT,A.SNAME,A.MEAL,A.RUTNO FROM STUDENT_RECORD_DATABASE A,DIVISION B,HNM C WHERE A.DIVID=B.DIVID AND A.HID=C.HID AND " & STR & ""
   Set rs = cn.Execute(sql)
End If
   Set DataReport2.DataSource = rs
   DataReport2.Show
   End Sub


Please help
Posted
Updated 7-Feb-13 22:21pm
v2

I think your code segment is incomplete but I would suggest you could combine fields in your query to make a new columns so:

sql = "SELECT A.ROLLNO, A.FIRST_NAME,A.MIDDLE_NAME,A.LAST_NAME,A.FIRST_NAME || ' ' || A.MIDDLE_NAME || ' ' || A.LAST_NAME AS FULLNAME A.ADDRESS, A.GRADE, B.DIV, A.BLOOD_GROUP, C.HOUSE, A.DATE_OF_BIRTH, A.TRANSPORT, A.SNAME, A.MEAL, A.RUTNO FROM STUDENT_RECORD_DATABASE A,DIVISION B,HNM C WHERE A.DIVID=B.DIVID AND A.HID=C.HID AND " & STR & ""

You can then bind to the column FULLNAME You need to worry about rows where one or all of the names are 'null' in the database and also you will get some odd spacings if thet row has blanks for one of the name components but there are ways of dealing with that which can explore for yourself.

There's a good page on this at:

http://luckylarry.co.uk/programming-tutorials/oracle/join-columns-concatenate-strings-in-oracle-plsql-mysql/[^]
 
Share this answer
 
SELECT REPLACE(A.FIRST_NAME + ' ' || COALESCE(A.MIDDLE_NAME, '') || ' ' || A.LAST_NAME, '  ', ' ') AS FULLNAME


Explanation:

|| is the concatenation operator[^] (in SQL Server I would have used + )

COALESCE[^] handles any cases where MIDDLE_NAME is null and replaces it with and empty string

The REPLACE[^] around the outside also handles the missing MIDDLE_NAME situation and changes the double space that would occur with a single space to make everything nice and tidy
 
Share this answer
 
Comments
surkhi 8-Feb-13 4:38am    
sir can I write this code in my main sql as given above?
or sh'd write another one?
CHill60 8-Feb-13 4:42am    
just put it in your main sql ... I only did it this way because I was being lazy ... See Chris' solution for the full SQL.
surkhi 8-Feb-13 4:49am    
SIR, but when there were 3 RptTextBoxes
I set their data field as FIRST_NAME,MIDDLE_NAME,LAST_NAME respectively but now I have only 1 RptTextBox so what sh'd I set it's data field value???
I tried with first_name & " " & middle_name & " " & last_name
but error shows field not found.......
Chris Reynolds (UK) 8-Feb-13 4:54am    
You should set it to FULLNAME as I suggested in my sample. Basically you are creating a pseudo-column with your SQL so you can set your RptTextBox to point to that new column
surkhi 8-Feb-13 4:51am    
If I left it's data field empty then also error:
empty field not found
sir please suggest something...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900