Sql Tutorial Class


Custom column in sql query

Custom column in sql query




Custom column in sql query: at some point, the user must show another column name in the database table of the sql server. The column was already specified when creating the table on the sql server. But sometimes it shows another name / text to clarify the result. Like this situation, the user can use the custom name in the SQL selection command. When the user applies the name of the custom column while manipulating in the SQL Select query. SQL Server returns the result with the column name specified by the user.

Custom column in sql server:

Syntax:
           Select column-name AS custom-column-name, Column-name AS Custom-column-name FROM Table-Name

Example.

Select * from ItemDetails  [Note: Display original column name from sql server database]

Select ItemCode as 'Code',ItemName as 'Name Of Item', ManufactureCompany as 'ProductCompany' from ItemDetails   [Note: Dispaly the custom column in sql server database]

[Note: For this query see the previous topics 
1. Creating Table. (Click here to more details ) and
2. Insert into table. (Click here to more dtails) ]

OR Execute the following Sql Command on sql server

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Create table in sql server database

Create Table ItemDetails
(
ItemCode int,
ItemName varchar(30),
ManufactureCompany varchar(50),
ExpiredDate date,
ItemSearialNo varchar (30),
ItemCategory varchar(30),
ItemQuantity int,
ItemPrice float,
ProductCountry varchar(30),
ReceivedDate date,
ItemImage image
)


Insert into ItemDetails values('1','Samsung Mobile','Samsung','12-10-2024','12-01-2050','S12345','Mobile','500','240','Korea','12-10-2025')
Insert into ItemDetails values('2','Samsung Pro','Samsung','12-10-2024','12-01-2050','SP1234','Mobile','100','300','Korea','12-10-2025')
Insert into ItemDetails values('3','Samsung Headphone','Samsung','12-10-2023','12-01-2053','SH2345','Headphone','50','50','Korea','12-10-2025')
Insert into ItemDetails values('4','iPhone','iPone','12-01-2024','12-01-2049','iP12345','Mobile','1000','500','United Stat','12-10-2025')
Insert into ItemDetails values('5','Apple Mobile','Apple','12-11-2024','12-01-2049','A12345','Mobile','200','300','United Stat','12-10-2025')
Insert into ItemDetails values('6','Apple Computer','Apple','12-02-2024','12-01-2050','A12343','Computer','200','400','United Stat','12-10-2025')
Insert into ItemDetails values('7','Apple Macbook','Apple','12-11-2024','12-01-2050','AM2345','Macbook','50','600','United Stat','12-10-2025')
Insert into ItemDetails values('8','Dell Computer','DELL','12-09-2024','12-01-2050','D02345','Computer','200','240','United Stat','12-10-2025')
Insert into ItemDetails values('9','Dell Laptop','DELL','12-09-2024','12-01-2050','DL2345','Laptop','30','240','United Stat','12-10-2025')
Insert into ItemDetails values('10','Apple Laptop','Apple','12-08-2024','12-01-2050','AL2345','Laptop','500','100','United Stat','12-10-2025')
Insert into ItemDetails values('11','Apple Headphone','Apple','12-12-2024','12-01-2050','AH2345','Headphone','50','20','United Stat','12-10-2025')
Insert into ItemDetails values('12','Sony Camera','Sony','12-11-2024','12-11-2050','SN2345','Camera','200','240','Japan','12-11-2025')
Insert into ItemDetails values('13','Sony Headphone','Sony','12-09-2024','12-01-2050','SNH345','Headphone','500','50','Japan','12-11-2025')
Insert into ItemDetails values('14','Ascer Computer','Ascer','12-09-2024','12-07-2050','AC2345','Computer','100','600','China','12-10-2025')
Insert into ItemDetails values('16','Borother Printer','Brother','12-09-2024','12-01-2050','B12345','Printer','200','200','China','12-10-2025')
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Executing Sql query command in Image 1



Executing Sql query command in Image 2



No comments:

Post a Comment