Display Count Of Records From The Same Table &> 1

Dec 27, 2007

How would I list the users in the users table that have duplicate IDs or count of IDs > 1?

The UserName field is unique.

State   UserName     First          Last         ID         City         Count
TX       Kkeaton         Kathryn     Keaton     1001     Dallas      2
TX       KakiKeaton    Kathryn     Keaton     1001     Dallas      2

I think I have to use a subselect? If I use group by then it won't show both records. It shows only one of them.

Thanks

Craig

View 4 Replies


ADVERTISEMENT

Dynamic View - Add A Column To Display Running Count In Table

Jul 22, 2014

I have a view created from only one table.

VW_Stats ( Tab_Name,Load_Status,User,....)

Tab_Name & Load_Status columns provides the information about Name of table and status of data getting loaded to this table.

To this I would like to add a column to display the running count in the table, I mean how many records so far loaded, as below the recordCount coming from the same table tbl_collection

Table_name Load_Status RecordCount User...
tbl_collection Running 1244 XYZ

View 7 Replies View Related

Enterprise Manager Cannot Display Table Records Or Run Query

Jul 23, 2005

I have a new installation of SQL Server 2000 Dev Edition on a Win2K3 Standard Edition Server that I used for development. I just set this machine up in th last week and installed all Win2K3 patches and then installed SQL2K and SP3a. I have a single named instance. I just noticed today that I cannot view table data or use the Query part of EM. When I right click a table and select Open Table->Return All Rows it gives me an error dialog "An unexpected error happened during this operation". While the EM is diplaying this dialog the EM screen looks like Internet Explorer and says "Action Canceled - You might not have permission to view this directory or page using the credentials you supplied." I believe that this is a EM issue as I cannot view table content on other remote server. ANy ideas? Might this be an IE security patch disallowing some connectivity ?--Frank--Message posted via http://www.sqlmonster.com

View 1 Replies View Related

Count Distinct In Large Table With 30M Records?

Jul 7, 2015

I have a task to count distinct records in a big table with roughly 30M records, performance is an important factor. Query is to be written to calculate weekly stats, weekly record number could be as high as 1M.

The actual result is like:
ID Policy
350235744Credit Cards
350235744PCI
350235744PCI Audit

So the final number for this particular Policy is 3

I can write the query like:

select count(distinct Incident_id) policy_name
from Reporting_DailyDlpDetail
Where (year(INSERT_DETECT_TS)=2015) and (month(INSERT_DETECT_TS) =6) and (day(INSERT_DETECT_TS) between 2 and 9)
This returns 526254 and costs 11 seconds to complete

or a query like:
Select distinct Incident_id, policy_name
from Reporting_DailyDlpDetail
Where (year(INSERT_DETECT_TS)=2015) and (month(INSERT_DETECT_TS) =6) and (day(INSERT_DETECT_TS) between 2 and 9)
This returns 749687 and costs roughly 1 minute to complete.

Result is different from the two queries, I believe the later gives correct number. How can I count the distinct based on a combo?Considering the size of data, what is the best and most efficient way to run the stats calculation against over 30 different scenarios (different policies and alert types) and not timeout?

View 9 Replies View Related

TSQL - Count The Number Of Records In A Table

Sep 24, 2007

Hi guys,
Is there any function to get the total number of records in a specific table?
(SQL SERVER 2000).
Thanks in advance,
Aldo.

View 3 Replies View Related

Simple Count Function - Show All Records For SSN In A Table

Jul 9, 2013

I want my query to list all SSNS that have more than one record in the table. I have this query:

Code:

SELECT SSN, name4, count(*) from [1099_PER]
group by SSN, name4
having count(SSN) > 1

It does retrieve the right SSNS and tells me how many times the SSN occurs in the table. However, I want my query results to display their full records.

For example

SSN NAME4 COUNT
123445555 WALTER - 4

I want the query to show me all four records for this SSN. I thought removing the count field would do this, but it still gives me only one instance of each SSN.

View 6 Replies View Related

SQL 2012 :: Count Records From Each Separate Data Table Corresponding To Feed

Nov 5, 2014

I have 1 table that is just a list of feeds. A, B, C, D etc (15 rows in total) and each feed has other information attached to it such as Full name, location etc etc. I am only interested in the Feed column.

Each feed then has a corresponding data table which contains a list of records. Eg Feed A data is contained in TableA, Feed B data is contains in TableB and so on.

Basically what I need is a combined table that shows the list of Feeds in the 1st Column ( So A, B, C, D…..) and then a second column which counts the records from each separate data table corresponding to that feed.

So the end result would look something like this:

Feed------No of Records
A----------4 (from TableA)
B----------7 (from TableB)
C----------8 (from TableC)
D----------1 (from TableD)

Possible?

View 2 Replies View Related

MDX: Count Records In Table A That Are Not In Table B

May 23, 2007

Hello all,



I would like to use MDX to identify "contracts" which are in a table A and not in a table B, and count them to have a total per "company".

It should be something like:



Contract / Flag contracts not in table B (1=yes, 0=not)

---------------------------------------------------------------

Contract 1 1

Contract 2 0

Contract 3 1

Contract 4 1

Contract 5 0

Contract 6 0

TOTAL 3



So far I know how to distinguish at contract level which records belong to table A and not table B, but I do not have the total for the company.



In SQL it should be something like that:

SELECT Company,count(*)

FROM tableA

left join tableB

on tableA.Contract = tableB.Contract

WHERE tableB.Contract is null

GROUP BY Company



Thanks,

Guillaume

View 3 Replies View Related

SQL Server 2008 :: Parent Records Ordering And Display Child Records Next To It?

Sep 7, 2015

declare @table table (
ParentID INT,
ChildID INT,
Value float
)
INSERT INTO @table
SELECT 1,1,1.2

[code]....

This case ParentID - Child 1 ,1 & 2,2 and 3,3 records are called as parent where as null , 1 is child whoose parent is 1 similarly null,2 records are child whoose parent is 2 , .....

Now my requirement is to display parent records with value ascending and display next child records to the corresponding parent and parent records are sorted ascending

--Final output should be

PatentID ChildID VALUE
33 1.12
null3 56.7
null3 43.6
11 1.2
null1 4.8
null1 4.6
22 1.8
null1 1.4

View 2 Replies View Related

How Do I Display A Count?

Mar 15, 2007

I want to display the number of records for each state in a database.  I'm using a strongly types dataset.  In my method, I have the followingSELECT     COUNT(ID) AS iTotal, STATEFROM         membersWHERE     (Suspend = 0)GROUP BY STATEORDER BY STATEIn the code behind of my page I have          Dim mateAdapter As New WAPTableAdapters.membersTableAdapter        Dim mates As WAP.membersDataTable        Dim mate As WAP.membersRow        mates = mateAdapter.GetDataState        For Each mate In mates            Select Case mate.STATE                Case "AK"                    LabelAK.Text = mate.ID.            End Select        Next  What should LabelAK.Text = mate.ID. be for me to be able to display the number of records that have 'AK' in the state field?Diane 

View 7 Replies View Related

COUNT Many But Display Just Once?

Apr 23, 2007

Hi, I have a table that I insert a member's country into every timesomeone signs up. What I'd like to do is pull information from the DBsuch that I can see each country and the number of users from each.For example:Argentina 10Brazil 5Canada 3I'm having trouble writing the SQL for this...any suggestions?Thanks,Erik

View 2 Replies View Related

Not Display The Letter Unless Count &>= 3

Jun 3, 2008

SELECT name = SUBSTRING(name, 1, 1),
total = COUNT(SUBSTRING(name, 1, 1))
FROM products
GROUP BY SUBSTRING(name, 1, 1)

the assignment said that,

quote:"Do not display the letter and count unless at least three product names begin with the letter."

but i got the errors when I try following.

WHERE total >= 3

quote:Msg 207, Level 16, State 1, Line 4
Invalid column name 'total'.

WHERE COUNT(SUBSTRING(name, 1, 1)) >= 3

quote:Msg 147, Level 15, State 1, Line 1
An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.


so what should I do?

View 3 Replies View Related

Display (field) But Only Count Managers

May 8, 2007

I need to figure out the number of managers without listing them. Label the column Number of Managers.

any help is appricated.


Number of Managers
-------------------------
6

View 3 Replies View Related

Transact SQL :: Display 0 With COUNT And GROUP BY

Aug 25, 2015

How can I display 0 when using COUNT and GROUP BY?I'm using SELECT CASE in my query. I was trying to use COALESCE but no result, COUNT result = 1. (there should be 0).

COALESCE((COUNT(DISTINCT (CAST((CASE
WHEN CurrStat = @Stat AND LogDate = @LogDate THEN Enumber ELSE 0 END) AS int)))), 0) AS InTrack,

View 5 Replies View Related

Retrieve Count From Stored Procedure And Display In Datagrid.

Feb 9, 2006

Hi Guys,
I have a sql procedure that returns the following result when I execute it in query builder:
CountE   ProjStatus
6            In Progress
3            Complete
4            On Hold
The stored procedure is as follow:
SELECT     COUNT(*) AS countE, ProjStatusFROM         PROJ_ProjectsGROUP BY ProjStatus
This is the result I want but when I try to output the result on my asp.net page I get the following error:
DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name Count.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with the name Count.Source Error:



Line 271: </asp:TemplateColumn>
Line 272: <asp:TemplateColumn>
Line 273: <itemtemplate> <%# DataBinder.Eval(Container.DataItem, "Count" )%> </itemtemplate>
Line 274: </asp:TemplateColumn>
Line 275: </columns>
My asp.net page is as follows:
<script runat="server">
Dim myCommandPS As New SqlCommand("PROJ_GetProjStatus")

' Mark the Command as a SPROC
myCommandPS.CommandType = CommandType.StoredProcedure
Dim num as integer
num = CInt(myCommand.ExecuteScalar)
'Set the datagrid's datasource to the DataSet and databind
Dim myAdapterPS As New SqlDataAdapter(myCommandPS)
Dim dsPS As New DataSet()
myAdapter.Fill(dsPS)

dgProjSumm.DataSource = dsPS
dgProjSumm.DataBind()

myConnection.Close()
</script>
 
<asp:datagrid id="dgProjSumm" runat="server"

BorderWidth="0"
Cellpadding="4"
Cellspacing="0"
Width="100%"
Font-Names="Verdana,Arial,Helvetica; font-size: xx-small"
Font-Size="xx-small"
AutoGenerateColumns="false">

<columns>
<asp:TemplateColumn HeaderText="Project Summary" HeaderStyle-Font-Bold="true" >
<itemtemplate> <%# BgColor(DataBinder.Eval(Container.DataItem, "ProjStatus" ))%> </itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<itemtemplate> <%# DataBinder.Eval(Container.DataItem, "Count" )%> </itemtemplate>
</asp:TemplateColumn>
</columns>
</asp:DataGrid>
Please help if you can Im havin real trouble here.
Cheers
 

View 3 Replies View Related

Retrieve Columns And Display Count For Two Different Data Sources

Jan 19, 2012

I am using Query Writer (should be SQL 2005) and have included the following code.

The end result: -should retrieve columns and display the count for two different data sources that were added by personnel in a specific department.

Problem: results are returned but not accurate. The code below works just fine and returns the results for all spot buy orders added by personnel in the sales department. However, I want to add a column in the same report that also counts blanket orders from the exact same table added by personnel in the sales department. The database uses views (v) in lieu of dbo.

Parameters:
@Add_Date_From SMALLDATETIME='',
@Add_Date_To SMALLDATETIME='',
@Last_name VARCHAR(50)='',
@First_Name VARCHAR(50)=''

Query:
SELECT
T1.Last_name,
T1.First_name,
T2.Position,
T3.Add_date,
COUNT(T4.PO_Type) AS 'Spot Buy Added'

[Code] ....

If I substitute COUNT(T4.PO_Type) AS 'Spot Buy Added' with COUNT(T4.PO_Type) AS 'Blanket Added' I also get accurate results for the blanket order. IE separately they work just fine. If I try to combine the two that is where the trouble begins.

What am I doing incorrectly when I try to add the criteria/code for the additional column to count the blanket orders?

View 9 Replies View Related

Reporting Services :: How To Display Count Of Column Groups

Oct 14, 2015

How to count the column group values and how to print the counts on every column for column group.

I used below expression to get the total column group count.

=CountDistinct(Fields!MMU.Value, "DataSet3")

View 8 Replies View Related

Analysis :: Query To Display Count Of Products When Month Is Primary

Sep 18, 2015

I am writing a query to display the count of products when a month is the primary month (Month where large sales happened)..Please consider the following query..

With Member ProductRank as
Rank([Date Due].[Calendar].currentmember,TopCount([Date Due].[Calendar].[Month],1,[Measures].[Sales Amount]))
Member PrimaryProd as
Count(Filter([Product].[Product].[Product],[Measures].ProductRank=1))
Select PrimaryProd on 0, Order([Date Due].[Calendar].[Month],PrimaryProd,bdesc) on 1 from [Sales]

Output:
 
It runs for 13 seconds on my laptop. I  have modified the query to get the results fast like With

Set MySet as TopCount([Date Due].[Calendar].[Month],1,[Measures].[Sales Amount])
Member ProductRank as
Rank([Date Due].[Calendar].currentmember,MySet)
Member PrimaryProd as
Count(Filter([Product].[Product].[Product],[Measures].ProductRank=1))
Select PrimaryProd on 0, Order([Date Due].[Calendar].[Month],PrimaryProd,Bdesc) on 1 from [Sales]

Output:

This query runs instantly and result is not the same. Am I missing something here?

View 2 Replies View Related

Display DB Records In Label?

Oct 16, 2006

A SQL Server 2005 stored procedure expects a parameter UserID depending upon which it retrieves the no. of records & OrderIDs corresponding to the UserID from a DB table (note that OrderID & UserID are two of the columns in the DB table). So for e.g. consider a user whose UserID=6 & the DB table has 3 records where UserID=6. In other words, there are 3 OrderID records of the user whose UserID=6, say, OrderID=8, OrderID=17 & OrderID=29. The stored procedure will finally return 2 columns - the OrderCount (which is 3 for UserID=6) & the OrderID (which will be 8, 17 & 29 for UserID=6). This is the stored procedure:ALTER PROCEDURE dbo.OrderCount    @UserID intASDECLARE    @OrderCount intSET @OrderCount = (SELECT COUNT(OrderID) FROM NETOrders WHERE UserID= @UserID)SELECT @OrderCount AS OrderCount, OrderIDFROMNETOrdersWHEREUserID = @UserIDIn a VB class file, I am invoking the stored procedure in a function named GetOrderCount which returns a SqlDataReader back to the calling ASPX page. I want the ASPX page to display the 3 OrderIDs of UserID=6 in a Label control. Unlike the DataBinding controls like DataList, DataGrid, Repeater controls, the Label control will not automatically loop through the recordset. So I tried to accomplish this using a For....Next loopDim i As IntegerDim sqlReader As SqlDataReaderiUserID = Request.Cookies("UserID").Value'ShopCart is the name of the class in the VB class fileboShopCart = New ShopCartsqlReader = boShopCart.GetOrderCount(iUserID)While (sqlReader.Read)    If (sqlReader.GetValue(0) > 1) Then        pnlLinks.Visible = True        For i = 1 To sqlReader.GetValue(0)            lblLinks.Text = sqlReader.GetValue(1)(i)        Next i    Else        pnlLinks.Visible = False    End IfEnd WhileBut this generates the following error:No default member found for type 'Integer'.pointing to the linelblLinks.Text = sqlReader.GetValue(1)(i)in the above shown ASPX code. Can someone please correct me & suggest how do I loop through the recordset so that I can display the records in a Label control?

View 8 Replies View Related

Display Grouped Records

Apr 11, 2008

I have the following sql table and would like to group the results by "StoryTitle" to display in a datalist. The Storytitle field in the datalist is a LabelID     StoryTitle       StoryAuthor      Rating     StoryID    Comments
1      About Me       goodyone            6          20           Great Story
2      About Me       goodyone            5          20           Love your work
3      Hello World    magicme             6          26           What a Story
4      Hello World    magicme             7          26           This Reminds me of...
I know i have to do something in the SQL Datasource statement. Not sure how to do it. here is my statement below
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:BrillConnectionString1 %>"
SelectCommand="SELECT * FROM [iaw.comments]">
</asp:SqlDataSource>
 

View 5 Replies View Related

Display Distinct Records?

Dec 7, 2011

TableName: Order_Archive
Fields:
orderid
load_date
filename
order_date
dollar

I load a file each week into a table, each file has unique orderid, load_date, filename, order_date and dollar. However the same orderid, order_date and dollar could appear in another file with different load_date and file_name.

File1:
orderid, load_date, file_name, order_date, dollar
'1000', '2011-01-01', 'File1', '2011-01-01', '101'
'1001', '2011-01-01', 'File1', '2011-01-01', '102'
'1002', '2011-01-01', 'File1', '2011-01-01', '103'

File2:
orderid, load_date, file_name, order_date, dollar
'1001', '2011-01-08', 'File2', '2011-01-01', '102'
'1002', '2011-01-08', 'File2', '2011-01-01', '103'
'1003', '2011-01-08', 'File2', '2011-01-01', '104'

Question:
whats is the best way to retrieve the distinct records that has the most recent load_date? expected results below:

Expected Results:
orderid, load_date, file_name, order_date, dollar
'1000', '2011-01-01', 'File1', '2011-01-01', '101'
'1001', '2011-01-08', 'File2', '2011-01-01', '102'
'1002', '2011-01-08', 'File2', '2011-01-01', '103'
'1003', '2011-01-08', 'File2', '2011-01-01', '104'

View 3 Replies View Related

Display Records For This Week

Apr 15, 2008

hi friends,

how to display the records for this week?

for today i used this query to dispaly the values

select count(*) from tbl_voting v,tbl_lkvotefor l where v.voteforid=l.voteforid and v.creationdatetime=CONVERT(VARCHAR(10), GETDATE(), 101)

View 4 Replies View Related

Display The Records For This Month

Apr 15, 2008

hi friends,

how to display the records for current month?

View 7 Replies View Related

Display Repeated Records

Mar 5, 2014

finding the solution for the below query?It displays repeated records.

select distinct ku.username,rro.role_name,rp.resource_type_code,kr.region_name,kc.currency_name,
fcr.cost_rule_id RULE,fcr.rate current_rate,pp.project_name,kou.org_unit_name ORG_UNIT
from

[code]....

View 2 Replies View Related

How To Display Records Only Once Using Groupby In

Mar 31, 2008

in my sql query,when it run then it displays records as follows

dt_id daily_type dates emp_mgmt_id emp_name etc--------
48 Electrical 03/14/2008 22 abc

----------
49 Mechanical 03/14/2008 35 xyz

-------------
48 Electrical 03/14/2008 22 abc

----------
49 Mechanical 03/14/2008 35 xyz

-------------

i want to display records only once like as follows

dt_id daily_type dates emp_mgmt_id emp_name etc--------
48 Electrical 03/14/2008 22 abc

----------
49 Mechanical 03/14/2008 35 xyz

-------------

if i use group by on some fields then it gives error as follows
Column 'Daily_Time_Entry.daily_type' is invalid in the select list because it is

not contained in either an aggregate function or the GROUP BY clause.

so how can i design query so records display only once not repeated,or is any
alternative,to solve this .


my sql query as follows

SELECT dl.dt_id, dl.daily_type, convert(char,dl.dt_date,101) as

dates,dl.emp_mgmt_id,
emp.emp_name,emp.employee_id,dl.project_type,dl.project_id,

dl.cec_job_id,
cec.cecjobname,dl.time_st,dl.time_ot,dl.time_dt,op.other_proj_id,


op.customer_name,op.project_name,op.owner_rep_phone_num1,dl.work_desc,
m.material_id,m.material_type,m.material_date, m.project_type

,m.project_id,
m.qty,m.description,m.material_unit_price,m.material_markup,

m.material_subtotal,
m.cec_job_id,m.location
FROM material m left outer join
Other_Project op on m.project_id=op.other_proj_id left outer join
Daily_Time_Entry dl on
dl.project_id =op.other_proj_id inner join Employee_Mgmt emp
on emp.emp_mgmt_id = dl.emp_mgmt_id inner join CEC_Job cec
ON dl.cec_job_id = cec.cec_job_id
where (dl.dt_date='3/14/2008'and m.material_date='3/14/2008') and
(dl.project_type='Other Project' and m.project_type = 'Other Project')
and (dl.cec_job_id=m.cec_job_id) and (dl.daily_type='Electrical') and
(dl.project_id='18')


uday

View 3 Replies View Related

How To Display Records In Ms Sql Using Pivot

Mar 13, 2008

hi i want to display records as per data in ms sql 2005
my data is as follows


Table name & fields are as follows :--

1) Ab_Corporate_Project

Fields are :

Ab_crp_id- int
Contract_no varchar
Project_no varchar
Field_order_no varchar
Ab_type varchar
Owner_id int

Records in Table Ab_Corporate_Project is as follows :

Ab_crp_id Contract_no Project_no Field_order_no Ab_type Owner_id

1 123 pr123 fd222 LS 2
2 323 pr323 fo122 GMS 3
3 243 pr243 fo233 EMC 1

2) Ab_Plant_Project

Fields are :

Ab_plant_id int
Service_order varchar
p_type varchar
Owner_id int

Records in Ab_Plant_Project is as follows

Ab_plant_id Service_order p_type Owner_id
1 so111 LS 1
2 so123 T&M 3
3 so110 EMC 2


3)Other_Project

Fields are

Other_proj_id int
Po varchar
Otype varchar
Owner_id int
Records in Other_Project is as follows

Other_proj_id Po Otype Owner_id
1 p123 LS 3
2 p22 EMC 3
3 p231 GMS 2

4)Owner_representative

Fields are
Owner_id int
Owner_names varchar

Records in Owner_representative are as follows

Owner_id Owner_names
<!--[if !supportLists]-->1 <!--[endif]-->john
<!--[if !supportLists]-->2 <!--[endif]-->amey
<!--[if !supportLists]-->3 <!--[endif]-->nickols

5)Employee_table

Fields are
emp_id int
Emp_name varchar

Records in Employee_table are as follows

Emp_id Emp_name
1 andrue
2 handy
3 sims
4 sandy

6)Daily_Time_Entry

Fields are
Dt_id int
Daily_type varchar
Dt_date datetime
Emp_id int
Project_type varchar
Project_id int
Time_st int
Time_ot int
Time_dt int
Records in Daily_Time_Entry are as follows

Dt_id Daily_type Dt_date Emp_id Project_type Project_id Time_st Time_ot
1 Elect 12/03/2008 1 AB Corporate 2 10 8
2 Mech 13/03/2008 2 AB Corporate 1 10 10
3 Mech 13/03/2008 1 AB Plant 2 5 6
4 Elect 13/03/2008 3 AB Plant 3 7 8
5 Mech 13/03/2008 2 Other Project 2 5 6
6 Elect 13/03/2008 4 Other Project 3 10 8

Where dt_date is in dd/mm/yyyy format
Also in project_type field -- AB Corporate is taken for Ab_Corporate_Project ,
AB Plant for Ab_Plant_Project, Other Project for Other_Project
This means if Project_type = AB Corporate then search into Ab_Corporate_Project
Else if Project_type = AB Plant then search into Ab_Plant_Project
Else if Project_type = Other Project then search into Other_Project

Now I want to display records as per datewise suppose I want to view records by date 13/03/2008

Record display as follows

Dt_id,Dt_date,emp_id,Emp_name, Project_type ,project_id, contract_no, service_order,ab_type,p_type,otype,owner_id,owner_name,time_st,time_ot

So how can I write query to display records as per datewise display
Plz send me a query for this solution

View 1 Replies View Related

Display TODAY's Records...

Sep 1, 2006

I am saving files in SQL Server 2005 with a datetime field called news_date_time and I want to display all today's records regardless of the record time.



I tried this code but didn't work..


[code]
SqlCommand sql_command = new SqlCommand("SELECT * FROM files_news WHERE news_date_time = TODAY ORDER BY news_date_time DESC", sql_connection);
[/code]

View 12 Replies View Related

Query To Display Most Active Records

Feb 11, 2005

Hello,

I have two tables, Promotion and Promolocation. The Promotion table is used to set up promotions or sales, and consists of a PromoID, StartDate, and EndDate. Each PromoID is referenced in the Promolocation table, which is used to assign items to a promotion for various locations or stores. The Promolocation table consists of PromoID, LocID, SkuID, PromoPrice, and DiscLevel.

There are times where an item or SkuID will exist in more than one promotion, however, our application is currently not intelligent enough to determine which promotion to use, so it sets the active promotion based on the StartDate being before other promotions' StartDate and the EndDate being after other promotions' EndDate.

I want to find all promoid's where a sku exists in more than one promotion. I want to signify which promotion is active, using 1 as the first active promotion, 2 as the next active, 3 as the next, etc. To determine which promotion is the first active promotion, the StartDate must be before any of the other promotions' StartDate, and the EndDate must be after other promotions' EndDate. If the promotions' StartDate is after the other promotions' StartDate but not before the other promotions' EndDate, and the EndDate is before or on other promotions' EndDate, then that's the second active promotion. If the StartDate is the same as other promotions' StartDate, but the EndDate is before other promotions' EndDate, then that's the third active promotion.

For example:

PromoID StartDate EndDate
------- --------- -------
PROMO1 1/1/2004 1/1/2006 (1st Active Promotion)
PROMO2 2/1/2004 1/1/2006 (2nd Active Promotion)
PROMO3 1/1/2004 12/1/2005 (3rd Active Promotion)

Here's a query I am using to display all active promotions:

select
pl.promoid,
pr.startdate,
pr.enddate,
pl.locid,
pl.skuid,
pl.promoprice,
pl.disclevel
from
promolocation pl
inner join
promotion pr
on
pl.promoid = pr.promoid
where
pr.enddate >= getdate()

Thanks for your help.

D

View 4 Replies View Related

How To Display Unmatched Records In Two Tables

Feb 28, 2008

I would like to build a query that will return all the records in Table1 that will not match with records in table 2. All colums in table 1 have NULL values. Only one column is populated with state abreviations.

SELECT nvl(field1, 0),
field2,
field3,
nvl(field4, 0),
nvl(field5, 0),
nvl(field6, 0)
FROM TBL1
-------------------------------------------
Result: Record count 3000.

Only field3 is populated everything else is null.

select field3 from tbl1 group by field2 - record count = 48



SELECT nvl(field1, 0),
field2,
field3,
nvl(field4, 0),
nvl(field5, 0),
nvl(field6, 0)
FROM TBL2

-------------------------------------

Result Record count = 0

------------------------------------------------------
SELECT nvl(field1, 0),
field2,
field3,
nvl(field4, 0),
nvl(field5, 0),
nvl(field6, 0)
FROM TBL1
minus
SELECT
nvl(field1, 0),
field2,
field3,
nvl(field4, 0),
nvl(field5, 0),
nvl(field6, 0)
FROM tbl2
---------------------------
Result: Record Count = 48

I used the left join and it didn't work.


I would like to build a query that will display all 3000 records.


Any help will be appreciated.

thank you!

View 4 Replies View Related

How Not To Display Number Of Records In SQLCMD

Jan 26, 2008

I would like to run a SELECT statement using the SQLCMD, however, I do not like the count of records be displayed after the execution. How do I do that?

Thanks in advance.

View 1 Replies View Related

Analysis :: MDX Display All Dimension Records

Jun 15, 2015

If I have a dimension with 3 records like this:

BrokerDimId  BrokerNm
1  Broker1
2  Broker2
3  Broker3

And I have a fact table that has 2 rows that join back to the first 2 dimension rows like this:

BrokerDimId  Amt
1  $100
2  $200

I want to create the mdx so that I get all of the dimension rows, even if there is no record in the fact table for it and just default the amount to 0, like this

BrokerDimId  Amt
1  $100
2  $200
3  $0

Is this possible using MDX?

View 2 Replies View Related

Transact SQL :: Display Records According To Date

Oct 2, 2015

I have a table that have student names and their birth dates just like below

a) tblStudentInfo

which shows records like below (Birth Dates are shown in Year-Month-Day format)

ID   StudentName        BirthDate   
1     ABC                       2002-12-25 
2     DEF                        2002-09-10  
3     GHI                        2002-09-19 
4     JKL                        2002-06-10 

[code]...

I want to perform a query that should display the upcoming birthday of all students according to today.Lets say, today is 2015-10-02, so the query should display the result according to today's date just like below

ID   StudentName        BirthDate   
1     ABC                       2002-12-25 
2     VWX                      2002-01-01
3     STU                        2002-02-03 
4     PQR                     2002-03-05 

[code]...

View 3 Replies View Related

Display Number Of Records Processed

Aug 20, 2007

I've got a stored procedure that processes a TON of records...

What I would liek to do is to write a row to a "progress" table which shows how many rows have actually been processed.

I have a simple counter defined in the procedure:

SET @COUNTER = 0

Each time the procedure loops through, it increments by 1:

SET @COUNTER = @COUNTER + 1

What I would like to do is write rows to a PROCESS table which would reads:

PROCESSED 1000 rows
PROCESSED 2000 rows
PROCESSED ...... rows
etc.

I have a slight idea how to pull this off, but not sure about the whole even number thing by 1000.

If anyone has any insight it would be greatly appreciated!!

Thanks in advance!

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved