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)
 Select X% per group

Author  Topic 

crownclit
Starting Member

20 Posts

Posted - 2007-07-29 : 08:44:08
I would like to select 10% of orders (tblOrder) for every company in tblCompany but having difficulties to construct proper T-SQL select statement.

Could anyone please help?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-29 : 08:52:06
Please post your table structure, sample data and expected result


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

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-29 : 12:49:01
SELECT Company, OrderNumber
FROM (SELECT Company, OrderNumber, NTILE(10) OVER (PARTITION BY Company ORDER BY OrderDate) AS tile FROM tblOrder)
) AS r
WHERE tile = 1
ORDER BY Company, OrderNumber



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

crownclit
Starting Member

20 Posts

Posted - 2007-07-29 : 21:25:48
Hi Guys
I’m not sure how to attach file in this forum so I’ve decided to paste SQL for the tables

TABLES
-----------------------------------------------------------------------------------------------------------
CREATE TABLE [dbo].[Address](
[AddressID] [uniqueidentifier] ROWGUIDCOL NOT NULL CONSTRAINT [DF_Address_AddressID] DEFAULT (newid()),
[Address1] [varchar](50) NULL,
[Address2] [varchar](50) NULL,
[Address3] [varchar](50) NULL,
[Suburb] [varchar](50) NULL,
[StateID] [numeric](18, 0) NULL,
[Postcode] [nvarchar](10) NULL,
[DPID] [varchar](200) NULL,
[CreateUserName] [nvarchar](50) NOT NULL,
[CreateDateTime] [datetime] NOT NULL,
[UpdateUserName] [nvarchar](50) NULL,
[UpdateDateTime] [datetime] NULL,
[Timestamp] [timestamp] NOT NULL,
CONSTRAINT [PK_Address] PRIMARY KEY CLUSTERED
(
[AddressID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
-----------------------------------------------------------------------------------------------------------
CREATE TABLE [dbo].[AddressState](
[AddressStateID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[StateTeritory] [varchar](30) NOT NULL,
[AddressStateName] [varchar](3) NOT NULL,
[CreateUserName] [varchar](50) NOT NULL,
[CreateDateTime] [datetime] NOT NULL,
[UpdateUserName] [varchar](50) NULL,
[UpdateDateTime] [datetime] NULL,
[Timestamp] [timestamp] NOT NULL,
[IsActive] [bit] NULL CONSTRAINT [DF_AddressState_IsActive] DEFAULT ((0)),
[AddressCountryID] [int] NULL,
CONSTRAINT [PK_States] PRIMARY KEY CLUSTERED
(
[AddressStateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
-----------------------------------------------------------------------------------------------------------
CREATE TABLE [dbo].[Form](
[FormID] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[ShowFormID] [varchar](50) NOT NULL,
[BatchID] [uniqueidentifier] NOT NULL,
[TeamID] [numeric](18, 0) NOT NULL,
[EventID] [numeric](18, 0) NOT NULL,
[FormEnteredByID] [numeric](18, 0) NULL,
[AddressID] [uniqueidentifier] NOT NULL,
[AddressValidationMethodID] [numeric](18, 0) NULL,
[AddressDuplicateCount] [numeric](18, 0) NULL,
[SalutationID] [numeric](18, 0) NULL,
[FirstName] [varchar](50) NULL,
[LastName] [varchar](50) NULL,
[PhoneNoTel] [varchar](50) NULL,
[FaxNoTel] [nvarchar](50) NULL,
[Email] [varchar](200) NULL,
[LightBulbTypeID] [numeric](18, 0) NULL,
[HotWaterSystemID] [numeric](18, 0) NULL,
[CustomerContactTypeID] [numeric](18, 0) NULL,
[MailingAddress1] [varchar](50) NULL,
[MailingAddress2] [varchar](50) NULL,
[MailingAddress3] [varchar](50) NULL,
[MailingSuburb] [varchar](50) NULL,
[MailingStateID] [numeric](18, 0) NULL,
[MailingPostcode] [varchar](10) NULL,
[MailingDPID] [varchar](50) NULL,
[MailingAddressValidationMethodID] [numeric](18, 0) NULL,
[BookingDate] [datetime] NULL,
[BookingTimeID] [numeric](18, 0) NULL,
[OrganisationID] [numeric](18, 0) NULL,
[GroupID] [numeric](18, 0) NULL,
[AgentID] [numeric](18, 0) NULL,
[ExternalCustomerID] [nvarchar](50) NULL,
[FormStatusID] [numeric](18, 0) NOT NULL CONSTRAINT [DF_Form_FormStatusID] DEFAULT ((0)),
[FormValid] [bit] NOT NULL CONSTRAINT [DF_Forms_FormValid] DEFAULT ((0)),
[DateFormReceived] [datetime] NOT NULL,
[SourceID] [varchar](8) NULL,
[HasCustSeenTNC] [bit] NOT NULL CONSTRAINT [DF_Forms_HasCustSeenTNC] DEFAULT ((0)),
[HasCustSignedForm] [bit] NOT NULL CONSTRAINT [DF_Forms_HasCustSignedForm] DEFAULT ((0)),
[ImageID] [varchar](64) NULL,
[ImageFolder] [varchar](200) NULL,
[ArchivedBy] [nvarchar](50) NULL,
[ArchiveDate] [datetime] NULL CONSTRAINT [DF_Forms_ArchiveDate] DEFAULT (getdate()),
[FormSuspendedReasonID] [numeric](18, 0) NULL CONSTRAINT [DF_Form_FormSuspendedReasonID] DEFAULT ((0)),
[SuspendedBy] [numeric](18, 0) NULL,
[SuspendedDate] [datetime] NULL,
[ReceiptedBy] [numeric](18, 0) NULL,
[ReceiptedDate] [datetime] NULL,
[ReconciledBy] [numeric](18, 0) NULL,
[ReconciledDate] [datetime] NULL,
[GeneralNotes] [varchar](500) NULL,
[PrintedCount] [numeric](18, 0) NULL,
[CreateUserName] [nvarchar](50) NOT NULL,
[CreateDateTime] [datetime] NOT NULL CONSTRAINT [DF_Forms_CreateDateTime] DEFAULT (getdate()),
[UpdateUserName] [nvarchar](50) NULL,
[UpdateDateTime] [datetime] NULL,
[Timestamp] [timestamp] NOT NULL,
[Surveyed] [bit] NULL CONSTRAINT [DF_Form_Surveyed] DEFAULT ((0)),
[SurveyExtractDate] [datetime] NULL,
CONSTRAINT [PK_Forms_1] PRIMARY KEY CLUSTERED
(
[FormID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
-----------------------------------------------------------------------------------------------------------
CREATE TABLE [dbo].[SalesInvoice](
[SalesInvoiceID] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[ShowSalesInvoiceID] [varchar](50) NULL,
[EventID] [numeric](18, 0) NOT NULL,
[FormID] [uniqueidentifier] NOT NULL,
[SalesInvoiceDate] [datetime] NOT NULL CONSTRAINT [DF_SalesInvoices_SalesInvoiceDate] DEFAULT (getdate()),
[CreateUserName] [nvarchar](50) NOT NULL,
[CreateDateTime] [datetime] NOT NULL CONSTRAINT [DF_SalesInvoices_CreateDateTime] DEFAULT (getdate()),
[UpdateUserName] [nvarchar](50) NULL,
[UpdateDateTime] [datetime] NULL,
[Timestamp] [timestamp] NOT NULL,
[SalesInvoicePaid] [bit] NULL CONSTRAINT [DF_SalesInvoice_SalesInvoicePaid] DEFAULT ((0)),
[SalesInvoicePaidDate] [datetime] NULL,
[SupplierInvoiceNo] [nvarchar](20) NULL,
CONSTRAINT [PK_SalesInvoice] PRIMARY KEY CLUSTERED
(
[SalesInvoiceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

-----------------------------------------------------------------------------------------------------------
CREATE TABLE [dbo].[SalesInvoiceItem](
[SalesInvoiceItemID] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[ShowSalesInvoiceItemID] [varchar](50) NOT NULL,
[SchemeID] [numeric](18, 0) NOT NULL,
[EventID] [numeric](18, 0) NOT NULL,
[SalesInvoiceID] [uniqueidentifier] NOT NULL,
[ProductID] [numeric](18, 0) NOT NULL,
[ProductQty] [int] NOT NULL,
[Cost] [money] NOT NULL,
[PaymentMethodID] [numeric](18, 0) NULL CONSTRAINT [DF_SalesInvoiceItem_PaymentMethodID] DEFAULT ((0)),
[PaymentReference] [varchar](20) NULL,
[MailProducts] [bit] NOT NULL CONSTRAINT [DF_SalesItems_MailProducts] DEFAULT ((0)),
[OrderFulfillmentRequestDate] [datetime] NULL,
[MailingOrganisationID] [numeric](18, 0) NULL CONSTRAINT [DF_SalesInvoiceItem_MailingOrganisationID] DEFAULT ((0)),
[MailingReference] [varchar](50) NULL,
[ProductReturned] [bit] NOT NULL CONSTRAINT [DF_SalesItems_ProductReturned] DEFAULT ((0)),
[DateOfReturn] [datetime] NULL,
[ReturnReference] [varchar](50) NULL,
[SalesInvoicePrintCount] [int] NOT NULL CONSTRAINT [DF_SalesItems_SalesInvoicePrintCount] DEFAULT ((0)),
[OrganisationID] [numeric](18, 0) NULL,
[GroupID] [numeric](18, 0) NULL,
[AgentID] [numeric](18, 0) NULL,
[CreateUserName] [nvarchar](50) NOT NULL,
[CreateDateTime] [datetime] NOT NULL CONSTRAINT [DF_SalesItems_CreateDateTime] DEFAULT (getdate()),
[UpdateUserName] [nvarchar](50) NULL,
[UpdateDateTime] [datetime] NULL,
[Timestamp] [timestamp] NOT NULL,
[ReasonForReturnID] [numeric](18, 0) NULL,
[ReturnProcessedBy] [numeric](18, 0) NULL,
CONSTRAINT [PK_SalesItems] PRIMARY KEY CLUSTERED
(
[SalesInvoiceItemID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
-----------------------------------------------------------------------------------------------------------
CREATE TABLE [dbo].[SystemUser](
[SystemUserID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[UserFirstName] [varchar](50) NULL,
[UserLastName] [varchar](50) NULL,
[Address1] [varchar](50) NULL,
[Address2] [varchar](50) NULL,
[Address3] [nvarchar](50) NULL,
[Suburb] [varchar](50) NULL,
[StateID] [numeric](18, 0) NULL,
[Postcode] [varchar](10) NULL,
[PhoneNoTel] [varchar](50) NULL,
[Mobile] [varchar](50) NULL,
[Email] [varchar](100) NULL,
[UserLogin] [varchar](50) NOT NULL CONSTRAINT [DF_SystemUsers_UserLogin] DEFAULT ('Unknown'),
[UserPassword] [binary](16) NOT NULL,
[UserPasswordRefreshDate] [datetime] NOT NULL CONSTRAINT [DF_SystemUsers_UserPasswordRefreshDate] DEFAULT (dateadd(month,(1),getdate())),
[UserTypeID] [numeric](18, 0) NOT NULL CONSTRAINT [DF_SystemUsers_UserType] DEFAULT ((6)),
[UserStatusID] [numeric](18, 0) NOT NULL CONSTRAINT [DF_SystemUsers_UserStatus] DEFAULT ((1)),
[OrganisationID] [numeric](18, 0) NULL,
[GroupID] [numeric](18, 0) NULL,
[CreateUserName] [varchar](50) NOT NULL CONSTRAINT [DF_SystemUsers_CreateUserID] DEFAULT ((1)),
[CreateDateTime] [datetime] NOT NULL CONSTRAINT [DF_SystemUsers_CreateDateTime] DEFAULT (getdate()),
[UpdateUserName] [varchar](50) NULL,
[UpdateDateTime] [datetime] NULL,
[Timestamp] [timestamp] NOT NULL,
[RunwayContactID] [varchar](255) NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[SystemUserID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UNIQUE_SystemUser_UserLogin] UNIQUE NONCLUSTERED
(
[UserLogin] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

-----------------------------------------------------------------------------------------------------------
CREATE TABLE [dbo].[Product](
[ProductID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[SchemeID] [numeric](18, 0) NOT NULL CONSTRAINT [DF_Product_SchemeID] DEFAULT ((0)),
[LightBulbTypeRequirementID] [numeric](18, 0) NOT NULL,
[HotwaterSystemRequirementID] [numeric](18, 0) NOT NULL,
[ProductName] [varchar](100) NULL,
[DetailedProductDescription] [varchar](500) NULL,
[StockCode] [varchar](20) NULL,
[AbatementCredit] [decimal](18, 2) NOT NULL,
[Commission] [money] NULL,
[CostToCustomer] [money] NULL,
[CreateUserName] [varchar](50) NOT NULL,
[CreateDateTime] [datetime] NOT NULL CONSTRAINT [DF_Products_CreateDateTime] DEFAULT (getdate()),
[UpdateUserName] [varchar](50) NULL,
[UpdateDateTime] [datetime] NULL,
[Timestamp] [timestamp] NOT NULL,
CONSTRAINT [PK_Product] PRIMARY KEY CLUSTERED
(
[ProductID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
-----------------------------------------------------------------------------------------------------------
CREATE TABLE [dbo].[OrganisationGroup](
[OrganisationGroupID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[OrganisationID] [numeric](18, 0) NOT NULL,
[OrganisationGroupName] [varchar](50) NOT NULL,
[CreateUserName] [nvarchar](50) NOT NULL,
[CreateDateTime] [datetime] NOT NULL CONSTRAINT [DF_OrganisationGroups_CreateDateTime] DEFAULT (getdate()),
[UpdateUserName] [nvarchar](50) NULL,
[UpdateDateTime] [datetime] NULL,
[Timestamp] [timestamp] NOT NULL,
[RunwayCompanyID] [varchar](255) NULL,
[Address1] [varchar](200) NULL,
[Address2] [varchar](200) NULL,
[Address3] [varchar](200) NULL,
[Suburb] [varchar](50) NULL,
[Postcode] [nchar](10) NULL,
[StateID] [numeric](18, 0) NULL,
[AddressCountryID] [int] NULL,
[PhoneNo] [varchar](50) NULL,
[MobileNo] [varchar](50) NULL,
[Fax] [varchar](50) NULL,
[Email] [varchar](200) NULL,
[ContactName] [varchar](50) NULL,
[BTRNumber] [varchar](50) NULL,
[ABN] [varchar](50) NULL,
[Zone] [varchar](50) NULL,
CONSTRAINT [PK_OrganisationGroups] PRIMARY KEY CLUSTERED
(
[OrganisationGroupID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
-----------------------------------------------------------------------------------------------------------
ALTER VIEW [dbo].[vwEBG_Events] AS
SELECT

CASE
-- 'Trades'
WHEN [dbo].[Event].[EventName] LIKE 'Trades - Residential%' THEN 'Trades'
WHEN [dbo].[Event].[EventName] LIKE 'Trades - Commercial%' THEN 'Trades'
WHEN [dbo].[Event].[EventName] LIKE 'Tradies Rebate%' THEN 'Trades'
-- 'Commercial'
WHEN [dbo].[Event].[EventName] LIKE 'Commercial - Commercial%' THEN 'Commercial'
-- 'Licenced Agent'
WHEN [dbo].[Event].[EventName] LIKE 'Licenced Agent - Residential%' THEN 'Licenced Agent'
WHEN [dbo].[Event].[EventName] LIKE 'Licenced Agent - Commercial%' THEN 'Licenced Agent'
-- 'Community Agent'
WHEN [dbo].[Event].[EventName] LIKE 'Community Agent - Residential%' THEN 'Community Agent'
WHEN [dbo].[Event].[EventName] LIKE 'Community Agent - Commercial%' THEN 'Community Agent'
-- 'Councils'
WHEN [dbo].[Event].[EventName] LIKE 'Councils - Residential%' THEN 'Councils'
WHEN [dbo].[Event].[EventName] LIKE 'Councils - Commercial%' THEN 'Councils'
-- 'Bright Kids'
WHEN [dbo].[Event].[EventName] LIKE '%Kids%' THEN 'Kids'
-- 'Employee Programs'
WHEN [dbo].[Event].[EventName] LIKE 'Employee Programs - Residential%' THEN 'Employee Programs'
-- 'Unsuspended'
WHEN [dbo].[Event].[EventName] LIKE '%Reprocess%' THEN 'Unsuspended'
ELSE 'Error, View vwEBG_EventName needs to be modified to include this Event In EventGroup column'
END AS EventGroup,
[dbo].[Event].[EventName],
[dbo].[Event].[EventID]
FROM [dbo].[Event] WITH (NOLOCK)
INNER JOIN dbo.Form WITH (NOLOCK) ON dbo.Event.EventID = dbo.Form.EventID
INNER JOIN dbo.FormStatus WITH (NOLOCK) ON dbo.Form.FormStatusID = dbo.FormStatus.FormStatusID
INNER JOIN dbo.CustomerContactType WITH (NOLOCK) ON dbo.Form.CustomerContactTypeID = dbo.CustomerContactType.CustomerContactTypeID
WHERE
[dbo].[CustomerContactType].[CustomerContactTypeName] NOT IN ('EOI', 'Exclusion') AND
[dbo].[Form].[BookingDate] = '1/1/1900 12:00:00 AM' AND
[dbo].[FormStatus].[FormStatusID] NOT IN (0) AND
[dbo].[Event].[EventID] NOT IN (0,12,25)
GROUP BY [dbo].[Event].[EventName],[dbo].[Event].[
Go to Top of Page

crownclit
Starting Member

20 Posts

Posted - 2007-07-29 : 21:34:03
Last line for the [vwEBG_Events] view should be
GROUP BY [dbo].[Event].[EventName],[dbo].[Event].[EventID]

Anyway – Below is the select statement which at this moment gives me all records for every company (OrganisationGroupName).
I would like to get similar statement but only with 10% of record for every OrganisationGroupName.

----------------------------------------------------
SELECT TOP (100) PERCENT dbo.Form.ShowFormID, dbo.Form.DateFormReceived, dbo.Form.FirstName + ', ' + dbo.Form.LastName AS CustomerName,
dbo.Form.PhoneNoTel,
dbo.Address.Address1 + ', ' + dbo.Address.Suburb + ', ' + dbo.Address.Postcode + ', ' + dbo.AddressState.AddressStateName AS Address,
SUM(dbo.SalesInvoiceItem.ProductQty) AS ProductQty, dbo.Product.HotwaterSystemRequirementID,
dbo.SystemUser.UserFirstName + ', ' + dbo.SystemUser.UserLastName AS InstallerName, dbo.vwEBG_Events.EventGroup, dbo.Form.SuspendedDate,
dbo.Form.FormStatusID, dbo.OrganisationGroup.OrganisationGroupName
FROM dbo.Form WITH (NOLOCK) INNER JOIN
dbo.SalesInvoice WITH (NOLOCK) ON dbo.Form.FormID = dbo.SalesInvoice.FormID INNER JOIN
dbo.SalesInvoiceItem WITH (NOLOCK) ON dbo.SalesInvoice.SalesInvoiceID = dbo.SalesInvoiceItem.SalesInvoiceID INNER JOIN
dbo.Product WITH (NOLOCK) ON dbo.SalesInvoiceItem.ProductID = dbo.Product.ProductID INNER JOIN
dbo.SystemUser WITH (NOLOCK) ON dbo.SalesInvoiceItem.AgentID = dbo.SystemUser.SystemUserID INNER JOIN
dbo.Address WITH (NOLOCK) ON dbo.Form.AddressID = dbo.Address.AddressID INNER JOIN
dbo.AddressState WITH (NOLOCK) ON dbo.Address.StateID = dbo.AddressState.AddressStateID INNER JOIN
dbo.vwEBG_Events WITH (NOLOCK) ON dbo.Form.EventID = dbo.vwEBG_Events.EventID INNER JOIN
dbo.OrganisationGroup ON dbo.SalesInvoiceItem.GroupID = dbo.OrganisationGroup.OrganisationGroupID
GROUP BY dbo.Form.ShowFormID, dbo.Form.DateFormReceived, dbo.Form.ReconciledDate, dbo.Form.FirstName, dbo.Form.LastName, dbo.Form.PhoneNoTel,
dbo.Address.Address1, dbo.Address.Suburb, dbo.Address.Postcode, dbo.AddressState.AddressStateName, dbo.SystemUser.UserFirstName,
dbo.SystemUser.UserLastName, dbo.Product.HotwaterSystemRequirementID, dbo.vwEBG_Events.EventGroup, dbo.Form.SuspendedDate,
dbo.Form.FormStatusID, dbo.Form.Timestamp, dbo.SalesInvoiceItem.GroupID, dbo.OrganisationGroup.OrganisationGroupName
HAVING (dbo.vwEBG_Events.EventGroup = 'Trades') AND (dbo.Form.FormStatusID = 2)
ORDER BY ProductQty DESC

----------------------------------------------------
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-30 : 02:43:23
And where are tblCompany and tblOrder as posted in original post?
Use the NTILE() function as described in my first answer.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

crownclit
Starting Member

20 Posts

Posted - 2007-07-30 : 05:41:20
I’ve tried to simplify this issue using tblCompany and tblOrder tables as principle is the same, but since you guys asked for table layouts i’ve had to published original ones.
Thanks Peso i will try to use your NTILE() function but it will take same time as i’m new to TSQL and would like to analyse and understand what you wrote.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-30 : 05:46:57
NTILE() function is available in Books Online (The SQL Server help file).



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -