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
 Other SQL Server Topics (2005)
 How to change the Menu/field name ??

Author  Topic 

kavi12345
Starting Member

19 Posts

Posted - 2012-03-05 : 00:38:50
hi,consider a table as 'A' which contains of fields like Name,Code,Place,Itemname,Quantity,Linetotal.so when i add a new record,it should display "Total" instead of "linetotal".how to change the field name only while displaying the record??Thanks in advance..

kavichakravarthi.R

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2012-03-05 : 01:30:43
use alias name

Select Name,Code,Place,Itemname,Quantity,Linetotal as Total from <table_name>

Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008
Go to Top of Page

kavi12345
Starting Member

19 Posts

Posted - 2012-03-05 : 02:31:59
@snthil...without using alias name also we can change the column name right? like this....select linetotal 'Total' from <Table1>..thanks for ur response..

kavichakravarthi.R
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2012-03-05 : 02:39:58
The way you specified and myself are same. But the Difference is CODE STANDARDS...

Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008
Go to Top of Page

kavi12345
Starting Member

19 Posts

Posted - 2012-03-05 : 05:45:44
By using alias,Cant we give words with space..ex..Have to give as "line total" instead of "total"....so,
select total as line total from table1..here line total has a space know..so, Is space acceptable while using alias concept?..if not,why is that??

kavichakravarthi.R
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-03-05 : 07:15:59
you can use spaces in an alias.

If you are using the result of a select statement for display (to a human being directly) then that's probably acceptable. If you are using an alias for a table then it's not good form.

For example

SELECT
e.[EmployeeName] AS [Employee Name]
, SUM(s.[SaleAmount]) AS [Employee Total Sales]
FROM
Employees AS e
JOIN Sales AS s ON s.[EmployeeID] = e.[EmployeeID]
GROUP BY
e.[EmployeeName]

Has a few examples of aliases.

In the SELECT part I alias the column names for output
in the FROM part I alias the tables to make my JOIN and SELECT shorter and easier to read.

Note that I use square brackets rather than apostrophes. This is less ambiguous because you aren't really encoding a string value.

When I alias table names I would never give them an alias with a space in.

When I alias columns then I generally don't use spaces because the output will be consumed by another program and spaces are just poor unless you are showing the results to a human.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

kavi12345
Starting Member

19 Posts

Posted - 2012-03-06 : 00:41:39
@Thanks fr ur great explanation.

kavichakravarthi.R
Go to Top of Page
   

- Advertisement -