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 2012 Forums
 Transact-SQL (2012)
 where Condition

Author  Topic 

ozandalkiran
Starting Member

13 Posts

Posted - 2015-04-20 : 07:59:43
hi friends
i have a table. i need the list of for 2 years 2013 and 2014 which records, difference percentege smaller or equal than 3 and which station percentage grater than 3 but literdiffernce equal or smaller than 288.
Pls Help Me

"where ReportPeriod >=201301 and ReportPeriod <=201412
and DifferencePercent <=3 + DifferencePercent > 3 and literdiffernce <=288 " its wrong :(

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2015-04-20 : 08:28:19
quote:
Originally posted by ozandalkiran

hi friends
i have a table. i need the list of for 2 years 2013 and 2014 which records, difference percentege smaller or equal than 3 and which station percentage grater than 3 but literdiffernce equal or smaller than 288.
Pls Help Me

"where ReportPeriod >=201301 and ReportPeriod <=201412
and DifferencePercent <=3 + DifferencePercent > 3 and literdiffernce <=288 " its wrong :(

Your syntax is incorrect, and the column names don't match with what you are describing. What you are describing seems more like this (assuming that you have a column named StationPercent in your table):
where 
ReportPeriod >='20130101'
and ReportPeriod < '20150101'
and DifferencePercent <= 3
and StationPercent > 3
and literdiffernce <=288
Go to Top of Page

ozandalkiran
Starting Member

13 Posts

Posted - 2015-04-20 : 08:49:04
quote:
Originally posted by James K

quote:
Originally posted by ozandalkiran

hi friends
i have a table. i need the list of for 2 years 2013 and 2014 which records, difference percentege smaller or equal than 3 and which station percentage grater than 3 but literdiffernce equal or smaller than 288.
Pls Help Me

"where ReportPeriod >=201301 and ReportPeriod <=201412
and DifferencePercent <=3 + DifferencePercent > 3 and literdiffernce <=288 " its wrong :(

Your syntax is incorrect, and the column names don't match with what you are describing. What you are describing seems more like this (assuming that you have a column named StationPercent in your table):
where 
ReportPeriod >='20130101'
and ReportPeriod < '20150101'
and DifferencePercent <= 3
and StationPercent > 3
and literdiffernce <=288




its is not working return 0 record.
shoulde be return many record
below all query

use PUMPOMAT_HO
SELECT [RID]
,[ReportPeriod]
,[MainCompanyLicenseCode]
,[EPDKLicenseCode]
,[StationID]
,[DealerID]
,[EPDKProductNameID]
,[EPDKProductName]
,[ProductID]
,[PeriodStartStock]
,[TankDelivery]
,[TotalSalesVolume]
,[ClosingTankVolume]
,[DescriptionID]
,[Description]
,[Status]
,[Approve]
,[IsSent]
,[IsClosed]
,[IsDeleted]
,[EPDKDescriptionID]
,[CreatedBy]
,[CreationTime]
,[UpdatedBy]
,[UpdatedTime]
,[UpdateSource]
,[TURPAKSpecialStatusID]
,[MinSampleTime]
,[MaxSampleTime]
,[ReconciliationStatus]
,[CalculatedClosingVolume]
,[LiterDifference]
,[DifferencePercent]
,[PeriodStartStockEx]
,[TankDeliveryEx]
,[ClosingTankVolumeEx]
,[TankDeliveryCalc]
,[CalculatedSalesvolume]
,[LiterDifferenceForSale]
,[DifferentPercentForSale]
,[KoyPompaSeyyarDolum]
,[SubStationDeliveryVolume]
FROM [PUMPOMAT_HO].[dbo].[EPDK_Table04_MounthlyDealerSum_Group]
where ReportPeriod >=201301
and ReportPeriod <=201412
and DifferencePercent <=3
and DifferencePercent >3
and LiterDifference <= 288
Go to Top of Page

ozandalkiran
Starting Member

13 Posts

Posted - 2015-04-20 : 08:55:28
quote:
Originally posted by ozandalkiran

quote:
Originally posted by James K

quote:
Originally posted by ozandalkiran

hi friends
i have a table. i need the list of for 2 years 2013 and 2014 which records, difference percentege smaller or equal than 3 and which station percentage grater than 3 but literdiffernce equal or smaller than 288.
Pls Help Me

"where ReportPeriod >=201301 and ReportPeriod <=201412
and DifferencePercent <=3 + DifferencePercent > 3 and literdiffernce <=288 " its wrong :(

Your syntax is incorrect, and the column names don't match with what you are describing. What you are describing seems more like this (assuming that you have a column named StationPercent in your table):
where 
ReportPeriod >='20130101'
and ReportPeriod < '20150101'
and DifferencePercent <= 3
and StationPercent > 3
and literdiffernce <=288




its is not working return 0 record.
shoulde be return many record
below all query

use PUMPOMAT_HO
SELECT [RID]
,[ReportPeriod]
,[MainCompanyLicenseCode]
,[EPDKLicenseCode]
,[StationID]
,[DealerID]
,[EPDKProductNameID]
,[EPDKProductName]
,[ProductID]
,[PeriodStartStock]
,[TankDelivery]
,[TotalSalesVolume]
,[ClosingTankVolume]
,[DescriptionID]
,[Description]
,[Status]
,[Approve]
,[IsSent]
,[IsClosed]
,[IsDeleted]
,[EPDKDescriptionID]
,[CreatedBy]
,[CreationTime]
,[UpdatedBy]
,[UpdatedTime]
,[UpdateSource]
,[TURPAKSpecialStatusID]
,[MinSampleTime]
,[MaxSampleTime]
,[ReconciliationStatus]
,[CalculatedClosingVolume]
,[LiterDifference]
,[DifferencePercent]
,[PeriodStartStockEx]
,[TankDeliveryEx]
,[ClosingTankVolumeEx]
,[TankDeliveryCalc]
,[CalculatedSalesvolume]
,[LiterDifferenceForSale]
,[DifferentPercentForSale]
,[KoyPompaSeyyarDolum]
,[SubStationDeliveryVolume]
FROM [PUMPOMAT_HO].[dbo].[EPDK_Table04_MounthlyDealerSum_Group]
where ReportPeriod >=201301
and ReportPeriod <=201412
and DifferencePercent <=3
and LiterDifference >3
and LiterDifference <= 288




shuld be add operator because, i need to sum of greater or equal to 3 and greater or equal 3 but smaller or equal to 288Litre

litre(288) = LiterDifference
Percentage (3) = LiterDifference

for example

Percentage Litre
2,5 300
3,5 280
1,5 120
15 260

For this exaple all record shoul be come . 5 records.

thanks for help


Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2015-04-20 : 10:11:47
You cannot do the following and expect to get any results:
FROM [PUMPOMAT_HO].[dbo].[EPDK_Table04_MounthlyDealerSum_Group]
where ReportPeriod >=201301
and ReportPeriod <=201412
and DifferencePercent <=3
and DifferencePercent >3

and LiterDifference <= 288
You are saying, give me all records where DifferencePercent is less than or equal to three, and by the way, those records must have DifferencePercentage greater than 3. That is a mathematical impossibility. So perhaps you don't want the "and DifferencePercent >3"
FROM [PUMPOMAT_HO].[dbo].[EPDK_Table04_MounthlyDealerSum_Group]
where ReportPeriod >=201301
and ReportPeriod <=201412
and DifferencePercent <=3
and LiterDifference <= 288
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2015-04-20 : 16:04:20
[code]
SELECT ...
FROM ...
WHERE ReportPeriod >= 201301
and ReportPeriod < 201501
and ((DifferencePercent <= 3) or (DifferencePercent > 3 and LiterDifference <= 288))

[/code]
Go to Top of Page
   

- Advertisement -