Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Concantenate two tables in a view

Author  Topic 

chava_sree
Yak Posting Veteran

56 Posts

Posted - 2008-08-12 : 21:42:46
How do i concantenate two table rows in a view..

I am trying to do this.

TABLE 1
-------
T_ID,
FIRSTNAME,
LASTNAME,
CITY,
SCHOOL

TABLE 2
-------
T_ID,
DEPARTMENT,
FACULTY NAME,
SUBJECT

I want to concatenate FIRSTNAME + LASTNAME + DEPARTMENT + SUBJECT as one string..

SELECT T1.FIRSTNAME + ' ' + T1.LASTNAME + '' + T2.DEPARTMENT + T2.SUBJECT FROM T1 Inner join T2 ON T1.T1_ID = T2.T2_ID

this doesn't work..

dexter.knudson
Constraint Violating Yak Guru

260 Posts

Posted - 2008-08-12 : 22:58:43
If I have understood your tables, Table 1 seems to be Student & Table2 seems to be subject. Do you want all students against every subject? If so this is a CROSS JOIN.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-13 : 00:14:41
quote:
Originally posted by chava_sree

How do i concantenate two table rows in a view..

I am trying to do this.

TABLE 1
-------
T_ID,
FIRSTNAME,
LASTNAME,
CITY,
SCHOOL

TABLE 2
-------
T_ID,
DEPARTMENT,
FACULTY NAME,
SUBJECT

I want to concatenate FIRSTNAME + LASTNAME + DEPARTMENT + SUBJECT as one string..

SELECT T1.FIRSTNAME + ' ' + T1.LASTNAME + '' + T2.DEPARTMENT + T2.SUBJECT FROM T1 Inner join T2 ON T1.T1_ID = T2.T2_ID

this doesn't work..



What doesn't work ?

Any error message ?

You are not getting the required result ? You have NULL in one of the column ?

Please explain.



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-13 : 00:18:03
change like this and try if it works

SELECT COALESCE(T1.FIRSTNAME + ' ','') + COALESCE(T1.LASTNAME + '','') + COALESCE(T2.DEPARTMENT,'') + COALESCE(T2.SUBJECT,'') FROM T1 Inner join T2 ON T1.T1_ID = T2.T2_ID
Go to Top of Page
   

- Advertisement -