Thursday, April 17, 2008

My Sql ServerQuery

--BetweenStatment
select CompName,OfferValidity from CompanyMaster where Offervalidity between '04/19/2008' and '04/21/2008' order by compname
--DistinceStatement
select distinct offerValidity from CompanyMaster
select AdvertisementMst.*,AdPosition.PageId,Adposition.Position,PageMaser.PageName
from AdvertisementMst,AdPosition,PageMaser
where AdvertisementMst.AdvertisementMstId=AdPosition.AdPositionId
--In StateMent
select * from CompanyMaster Where CompName In('2Much','Dhaval Super Store')
--LikeOrSearchKeyWord StateMent
select * from CompanyMaster where CompName like ('%2Much%')
--SoundEx Search StateMent
select * from CompanyMaster Where SoundEx(compname)= soundex('2Much')
--OrderBy Statement
--Assending Order
select * from CompanyMaster order by CompName asc
--Desending Order
select * from CompanyMaster order by CompName desc
--Count statement with Join Statement
select count(ProductMaster.ProductId) TotalProduct ,CompanyMaster.CompName from CompanyMaster,ProductMaster where CompanyMaster.companyId=35 and CompanyMaster.CompanyId=ProductMaster.Companyid group by CompanyMaster.CompName
--Alias StateMent
select tbl .CompName from CompanyMaster tbl
--Outer Join State ment
SELECT A1.store_name, SUM(A2.Sales) SALES
FROM Geography A1, Store_Information A2
WHERE A1.store_name = A2.store_name (+)
GROUP BY A1.store_name
--Concate Statement :Get Two ColumnData In On Column
select CompCity+''+CompName companyNameWithCity from CompanyMaster
--SubString Statement:Get Data of column with Specific Char limit
select Substring(CompName,1,3) CompPrefix from companyMaster
--Create View Statement: Get Data of Two Table in diffrent Column
create view Company_Product as select count(productMaster.ProductId) ProductCount,companyMaster.Compname CompanyName from companymaster,productmaster where companymaster.companyId=productmaster.companyId group by companymaster.compname
--Create index statement:
create index CompanyIndex on companyMaster(Compname,CompanyId)
--Alter Table
ALTER table customer add Gender char(1)
--Drop Table
DROP TABLE customer
--Truncat Table(Data only deleted from table
TRUNCATE TABLE customer
--Update statement
UPDATE Store_Information
SET Sales = 500
WHERE store_name = "Los Angeles"
AND Date = "Jan-08-1999"
--Delete statement
DELETE FROM Store_Information
WHERE store_name = "Los Angeles"

No comments: