Creating Data For A Histogram.
Jul 23, 2005
I have a table, TableA with amongst other fields, a field for Qty.
Qty can range from 0 to 100.
How do I count the number of rows with a qty between 1 and 10, 11 and
20, 21 and 30, and so on using one SQL statement?
Regards,
Ciarán
View 16 Replies
ADVERTISEMENT
Mar 20, 2008
Hi all -
I would like to know how in sql I can generate a histogram of data with a known range of values. Here is an example of what I would like to be able to generate.
I would like to see the count of how many values range from .0001 to .0002 and .0002 to .0003 and .0003 to .0004
up to .0019
Then I would like to see greater variation such as stepping every .005 instead of .0001 after .0019. So this would be .005 to .010, .010 to .015
VALUE
0.0001
0.0002
0.0001
0.0001
0.0001
0.0001
0.0006
0.0008
0.001
0.0012
0.0014
0.0016
0.0018
0.0017
0.0007
0.0019
0.002
0.005
0.006
INTERVAL FREQUENCY
------------------------- -------------------------
0 2762
0.0001 370
0.0002 338
0.0003 246
0.0004 175
0.0005 86
0.0006 41
0.0007 24
0.0008 12
0.0009 13
0.001 9
0.0011 10
0.0012 7
0.0013 5
0.0014 5
0.0015 4
0.0016 2
0.0017 1
0.0018 1
0.0019 2
0.005 26
0.01 8
0.015 5
0.02 3
0.025 0
0.03 1
View 3 Replies
View Related
May 8, 2008
I have a following code to "draw" a "histogram" :-)
use tempdb
go
declare @temp table
(id int identity(1,1)
,valuess int)
insert into @temp (valuess) values (64)
insert into @temp (valuess) values (12)
insert into @temp (valuess) values (23)
insert into @temp (valuess) values (45)
insert into @temp (valuess) values (30)
select
id
,valuess
,histogram = cast(replicate('*', valuess*0.4) as nvarchar(50))
,length = len(cast(replicate('*', valuess*0.4) as nvarchar(50)))
from @temp
order by valuess desc
Is there any better way to do it; maybe even a function?
Thanks :)
View 2 Replies
View Related
Oct 5, 2015
I would like to know what a particular session is waiting on (cpu, io, memory etc).
For that I try to figure out how to use extended events. I would prefer to avoid the use files written to db-server, why I tried "histogram target".
Well my attempt does not produce usefull output,
-- check current event sessions
SELECT a.name,
CASE WHEN b.name IS NOT NULL
THEN 'Started'
ELSE 'Stopped'
END AS current_state
[Code] ....
The intention was to get a pareto chart, to see the top wait events in the session. I would also like to see amount of cpu used. Based on this tuning effort could be prioritized.
View 6 Replies
View Related
Nov 1, 2006
HiI'm having problems following the tutorial on creating a data access layer - http://www.asp.net/learn/dataaccess/tutorial01cs.aspx?tabid=63 - when I try to compile in Visual Studio 2005 I get namespace could not be found. I followed exactly the tutorial - I created a dataset and added this code in my aspx page. <asp:GridView ID="GridView1" runat="server" CssClass="DataWebControlStyle"> <HeaderStyle CssClass="HeaderStyle" /> <AlternatingRowStyle CssClass="AlternatingRowStyle" />In my C# file I added these lines... using NorthwindTableAdapters; <<<<<this is the problem - where does this come from? protected void Page_Load(object sender, EventArgs e) { ProductsTableAdapter productsAdapter = new ProductsTableAdapter(); GridView1.DataSource = productsAdapter.GetProducts(); GridView1.DataBind(); }Thanks in advance
View 6 Replies
View Related
Sep 20, 2007
I am attempting to create a stored procedure that will launch at report runtime to summarize data in a table into a table that will reflect period data using an array type field. I know how to execute one line but I am not sure how to run the script so that it not only summarizes the data below but also creates and drops the table.
Any help would be greatly appreciated.
Current Table
Project | Task | Category | Fiscal Year | Fiscal Month | Total Hours
---------------------------------------------------------------------------------------------------------
Proj 1 | Task 1 | Cat 1 | 2007 | 01 | 40
Proj 1 | Task 1 | Cat 2 | 2007 | 02 | 20
Proj 1 | Task 1 | Cat 3 | 2007 | 03 | 35
Proj 1 | Task 1 | Cat 1 | 2008 | 01 | 40
Proj 1 | Task 1 | Cat 2 | 2008 | 02 | 40
Proj 1 | Task 1 | Cat 3 | 2008 | 03 | 40
Proposed Table
Project | Task | Category | Fiscal Month 01 | Fiscal Month 02 | Fiscal Month 03 | Fiscal Year
---------------------------------------------------------------------------------------------------------------------------------------------------
Proj 1 | Task 1 | Cat 1 | 40 | 0 | 0 | 2007
Proj 1 | Task 1 | Cat 2 | 0 | 20 | 0 | 2007Proj 1 | Task 1 | Cat 3 | 0 | 0 | 35 | 2007
Proj 1 | Task 1 | Cat 1 | 40 | 0 | 0 | 2008
Proj 1 | Task 1 | Cat 2 | 0 | 40 | 0 | 2008
Proj 1 | Task 1 | Cat 3 | 0 | 0 | 40 | 2008
Thanks,
Mike Misera
View 6 Replies
View Related
Oct 7, 2007
I am adding tables to a DB. I want to put table and column descriptions in as I go.
1. Is there a "Description" property for the table? I see in the column properties list a "description".
2. Once I have my descriptions all in, indexes set etc, is there a system stored procedure that I can run that will generate the data dictionay? (With a table description.)
Thanks
View 14 Replies
View Related
Mar 10, 2008
Hello, everybody.
In my web application, i'm using 2 tabels; Users(Username(PK), Pwd, Name, Deptid(FK)) n Dept(Deptid(PK), Deptname)).
For creating a Data Access Layer 4 my project, I added dataset as new item n followed the wizard 2 create the required functions.
I have a function GetUser(@uname, @pwd), which takes username n password as input. M using this for authentication purpose.
While executing it poping an ConstrainException.
Plz help me out.
I've tried 2 as clear as possible here. OR u may ask me any other questions for clear picture of the scenario.
Thanks and Regards,
Sankar.
View 1 Replies
View Related
Jun 11, 2008
I request you plz tell how to create Data Access Layer. I mean DataAccess.dll. So that I can call stored procedure from dataaccess.dll as below.
DataAccess.SqlHelper.ExecuteDataset(DataAccess.DSN.Connection("DBConnectionString"), CommandType.StoredProcedure, "SP_GetEmpIds");
I request you how can I add this stored procedures to DataAccess.dll and function. I am not having any idea in this area. I request you plz give me some suggestions to work with task.
View 3 Replies
View Related
Jun 29, 2005
I have a form with a drop down box so the user can select a quote.. When a quote is selected i need to populate a table of all the records associated with the quote id. I need the table to be created in such a way that the user can add new rows, delete rows and edit the data. Then all of the changes need to be written back to the database. Whats the most efficient/best way of doing this and if you have any ideas can you explain them as thoroughly as possible! I'm currently upgrading an access database to a sql server back end with an asp.net client and it's taking me a while to get to grips with all the changes!Thanks in advance,Chris
View 1 Replies
View Related
Aug 27, 2005
I use Visual Studio and VB.
If I want to create an SQL data table on the server, I go to Server
Explorer and make a small table with the corerct columns. Then I add
rows programatically as needed from the Application I'm working with.
It would suit me, for a current job, to be able to create the table itself programatically.
I don't know how to do this. Can it be done ? If so, could someone give
me a starter, please ? Four cols with a key in the first.
David Morley
View 1 Replies
View Related
Dec 7, 2000
When a new database is created in enterprise manager the path for the database and transaction logs are defaulted to d:mssql7data or wherever you installed SQL Server to initially. Is there a way to change the defaults to place the data on one drive and the logs on a different drive?
View 1 Replies
View Related
Mar 5, 2006
a number of time I have come accross developers using functions like
GetProduct()
GetProductTitle()
GetProductCategory()
to get the value of the data instead of just using queries / stored procedures
I have not understood why
can you please point to some good forum messages / blogposts / articles on this ?
Whats your take on this ?
View 8 Replies
View Related
Dec 1, 2014
I am doing some work in microstrategy reports and using SQL data cube. I am creating a summary report (Counting on Unique ID) in MS where when I put in a particular attribute/column from cube it splits the data count down into 2 separate values that I have defined in the select case statement of the SQL query.
I want to work out a ratio of the count unique ID between these two values but can't do this in MS report as it is not a physical column but summary split of data.Is there a way I can do this in SQL? My summary looks something like this:
N E
====================== =========================
**Y** N **Y** N
========= ========== ========= =========
570 140 89 56
Where the Y/N field is the one I have split down against the N/E column. I want to work out ratio between the 2 "Y" fields but in SQL. Here is a SQL example snapshot of my data:
Unique_ID New/Existing Application Attend_Interview
========= ======================== ================
12554445 E Y
65766879 N N
53375654 N Y
44323224 E N
93656786 E Y
wondering if I might be able to do a procedure or similar or something more dynamic in SQL query?
View 1 Replies
View Related
Jan 25, 2007
hi, i'm trying to create a table and populate it with data from another database residing on the same server. i've done this on oracle using tables within the same database and am just making a first effort with the added twist of a different database. this is what i've been doing so far...
CREATE TABLE facility_dimension
(
fac_id INT IDENTITY(1,1),
tri_fac_id CHAR(17),
fac_nameVARCHAR(100),
street VARCHAR(100),
city VARCHAR(100),
county VARCHAR(50),
state VARCHAR(4),
longitude REAL,
latitude REAL,
PRIMARY KEY(fac_id)
)
SELECT tri_facility_id, facility_name, street_address,
city_name, county_name, state_abbr, fac_latitude,
fac_longitude
FROM TRI_2004.form_1;
....where TRI_2004 is the other database and form_1 is the table. the result is creation of the new table and then the output of the secondary query. i'm assuming this can even be done but if it can't that would be helpful to know as well. thanks in advance!
View 2 Replies
View Related
Jul 20, 2005
SQL Server 2000Is there any way to take sample data in my database and create an INSERT INTO script?I have a commercial application that I would like to include sample data, and instead of restoring a backup like I am doing now, I would like to first run a script that creates the database, stored procedures, etc, then run a script that inserts sample data if the customer so chooses.I know I can do this manually, but is there any way to create the script based on exisiting data?TIA-- Tim Morrison--------------------------------------------------------------------------------Vehicle Web Studio - The easiest way to create and maintain your vehicle related website.http://www.vehiclewebstudio.com
View 4 Replies
View Related
Jul 24, 2007
I am using SQLServer 8.
I have several files that were FTP'd from our legacy COBOL system. I am in the process of cleaning them up and saving them into CSV format.
I was told that I could use the BCP utility to import them into a SQL database, but the documentation I have is not real clear on that.
Does anyone have any suggestions for how to import these files? I have created the database but not the tables.
Thanks.
View 3 Replies
View Related
Nov 27, 2007
Hi need to create navigation that gets populated via database and is role based. below is the sql
CREATE TABLE [TopMenu] (
[MenuID] [int] IDENTITY (1, 1) NOT NULL ,
[Text] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Description] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ParentID] [int] NULL ,CONSTRAINT [PK_Menu] PRIMARY KEY CLUSTERED
(
[MenuID]
) ON [PRIMARY] ) ON [PRIMARY]
GO
INSERT INTO TopMENU
Select 'Property','Property', NULL
UNION ALL Select 'Portfolio','Portfolio', NULL
UNION ALL Select 'Capital Expenditure','PortfolioCapex', 1
UNION ALL Select 'Depreciation','PortfolioDepreciation', 1
UNION ALL Select 'Condition Audit','PortfolioCondition', 1
UNION ALL Select 'Historical Expenditure','PortfolioHisEx', 1
UNION ALL Select 'Property Details','PropertyDetail', 2
UNION ALL Select 'Assets','PropertyAsset', 2
UNION ALL Select 'Depreciation','PropertyDepreciation', 2
UNION ALL Select 'Capital Expenditure','PropertyExpenditure', 2
UNION ALL Select 'Insurance','PropertyInsurance', 2
UNION ALL Select 'Documents','PropertyDocuments', 2
UNION ALL Select 'Capex','PortfolioCapex', 3
UNION ALL Select 'Graph','PortfolioCapexGraph', 3
UNION ALL Select 'Graph','PortfolioDepreciationGraph', 4
UNION ALL Select 'Current Depreciation','PortfolioDepreciation', 4
UNION ALL Select 'WDV & Depreciation','PortfolioDepreciationWDV', 4
UNION ALL Select 'Assets','PropertyAsset', 8
UNION ALL Select 'Capex','PropertyCapex', 8
UNION ALL Select 'Depreciation','PropertyDepreciation', 8
UNION ALL Select 'Condition','PropertyCondition', 8
UNION ALL Select 'Expenditure','PropertyExpenditure', 8
UNION ALL Select 'Disposed','PropertyDisposed', 8
UNION ALL Select 'Capital Ex','PropertyExpenditure', 10UNION ALL Select 'Capital Ex Graph','PropertyExpenditureGraph', 10
GO
now clearly, I will have two top level navigation
property and portfolio. both property will have subsequent navigation and those subsequest navigation may or may not have another sets of navigation.
I need to display in a row style not in a drop down style for eg. If I am in portfolio link the navigation structure should be as below
Portfolio
Capital Expenditure | Depreciation | Condition Audit | Historical Expenditure
Capex | Graph
by default Capex should be selected. it should also highlight Portfolio, Capital Expenditure and Capex as Capex's parent is Capital Expenditure and Portfolio
I was thinking of using a 3 level datagrid. could someone please help me I am using asp.net 2.0 web application project with vb.net and sql server 2005
thanks in advance
View 9 Replies
View Related
Aug 4, 2005
Hi, I'm having some difficulty creating the SQL Statement for getting some data from a table:
I have the following table of data
__User___Votes___Month
__A_______14______2__A_______12______3__A_______17______4__A_______11______5
__B_______19______2__B_______12______3__B_______15______4
I want to beable to pull out the total number of votes a user has had over a period of months.
eg Total up each users users votes for months 4 and 5
that would give:
__User____TotalVotes
___A________28___B________15
An added complecation is that user B does not have any data for month 5
Any help or pointers would be fanstatic
Many thanks
View 3 Replies
View Related
Dec 1, 2005
Hello all,
I am having a lot of trouble with stored procedures. Could anyone help me out.
I have a table which contains a number of meetings. What I want to do is search this table, get out all the meetings for today and put them in a seperate table meetings today.
I can select the values, and I can insert the values.
But how do I store the values so that i can pass the results of the select to the insert?
Im also having a lot of trouble with storing date values.
ANy help would be greatly appreciated.
Regards,
Padraic Hickey
View 2 Replies
View Related
Mar 29, 2001
SQL7 SP3
Hi.
I have a table in which I want to create a delimited list of values from one field which I will be using for validation.
How can I do this without using a cursor to build the string. The SQL would be something like:
SELECT *
FROM myCrossRefTable
WHERE SourceTable = 'FieldValueList'
I'm looking to return on string like -
~value1~value2~value3~value4~value5
Thanks,
Craig
View 2 Replies
View Related
Jun 11, 2008
Hi All,
I am extracting source data which is in txt fille to OLE DB destination. But data of each day I want to save in different staging table. For Eg; tblProduct20081206, tblProduct20081207. How can it be done. I have seen lots of posting and script when destination is Txt. I want to use same table for staging but want to create different table for each day with adding date extension.
Please Help
View 2 Replies
View Related
Feb 27, 2008
I have written following SQL query, this creates temporary table, inserts rows into it. I need to create VIEW "vw_NumberOfAttachments" in the database. I initially created table using "CREATE TABLE" but then i got error as VIEW can not be filled by temporary table. Hence I am using DECLARE TABLE
--------------------------------
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE sp_GetViewNumberOfAttachments
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @emailMessageID bigint
DECLARE @metaDataStorageID bigint
DECLARE @numberOfAttachments int
DECLARE @AttachmentDetails TABLE
(
emailMessageID bigint,
metaDataStorageID bigint,
numberOfAttachments int
)
DECLARE ATTACHMENT_CURSOR CURSOR
FOR
SELECT emailMessageID, metaDataStorageID
FROM ppaEmailMessage
WHERE hasAttachments='true'
OPEN ATTACHMENT_CURSOR
FETCH NEXT FROM ATTACHMENT_CURSOR INTO @emailMessageID, @metaDataStorageID
WHILE @@FETCH_STATUS = 0
BEGIN
-- here the table name need to get dynamically the name of the attachment table
-- for a moment it is written as ppaMsOfficeDoc, but that should change dynamically
set @numberOfAttachments = (SELECT count(*) FROM ppaMsOfficeDoc WHERE metaDataStorageID = @metaDataStorageID)
INSERT INTO @AttachmentDetails(emailMessageID, metaDataStorageID, numberOfAttachments)
VALUES (@emailMessageID, @metaDataStorageID, @numberOfAttachments)
FETCH NEXT FROM ATTACHMENT_CURSOR INTO @emailMessageID, @metaDataStorageID
END
CLOSE ATTACHMENT_CURSOR
DEALLOCATE ATTACHMENT_CURSOR
IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_NAME = 'vw_NumberOfAttachments')
DROP VIEW vw_NumberOfAttachments
GO
CREATE VIEW vw_NumberOfAttachments
AS
SELECT @AttachmentDetails.emailMessageID, @AttachmentDetails.metaDataStorageID, @AttachmentDetails.numberOfAttachments
FROM @AttachmentDetails
GO
END
GO
----------------------
I am getting following errors:
-----------
Msg 102, Level 15, State 1, Procedure sp_GetViewNumberOfAttachments, Line 57
Incorrect syntax near 'vw_NumberOfAttachments'.
Msg 137, Level 15, State 2, Procedure vw_NumberOfAttachments, Line 3
Must declare the scalar variable "@AttachmentDetails".
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'END'.
-----------
Can anyone please suggest whats wrong in there? Many thanks
View 1 Replies
View Related
Jul 20, 2005
I have created a table with the following columns...Date(datetime),Actual (Int),Planned (Int)I need to insert weekending dates starting from 23/04/04 loopingthru'for the next 52weeks automatically into the date column.Then in the actual and planned colums, I need to insert a count ofsome records in the table.I will appreciate help on a SQL query to achieve this!
View 5 Replies
View Related
May 19, 2007
I'm trying to create a custom data flow destination, and it has a custom property that needs to get value from variable(similar to the FileNameVariable property of Raw File Destination), how can I do that?
View 5 Replies
View Related
Nov 28, 2007
Anyone know the syntax and function to create a self incrementing index whilst extracting data? I'm using the Derived Column tool. The extract will be a full extract everytime, not incremental.
Thanks.
View 4 Replies
View Related
Jun 27, 2007
I am using a matrix to display current and historical financial data. To do this, I am using 5 different datasets. Each dataset contains 1 row of data for a specific year for a specific account.
Now that problem I am having is displaying this data in a chart. When I create a new chart, it asks which dataset I would like to use. I do not want to use any specific dataset, I want to get chart's data from the matrix. Is this possible?
View 8 Replies
View Related
Jan 15, 2008
I would like to write a custom data source component for SSIS. I was wondering if there are any tutorials / examples for this that are available.
Thanks
View 1 Replies
View Related
Sep 11, 2006
I'm unable to create a field with the type varbinary(max). When I try doing this with Management Studio, it tells me that the maximum length is 8000 bytes. I've also tried creating the field with DDL as shown below, but that doesn't work either. If I create the varbinary field with a length of 8000 or less, it works fine. Is there some trick to using varbinary(max)?
Thank you.
create table images (filename nvarchar(250) primary key,photo varbinary(max))
View 4 Replies
View Related
Jul 2, 2007
Using SS2005, I am trying to create a Data-Driven Subscription to query off a value. I have the value in my stored procedure like:
Procedure dbo.sp_ReportMaster @myid int=null
When I run the report in the Reporting Services, it prompts for myid, which is fine. I then deployed the report to the Reports Manager and tried to create a Data-Driven Subscription. Where it says specify a command, I put in exec sp_ReportMaster. I put in the pertinent information, then it says, "The 'ReportMaster' has no parameters," even though I have the parameter in my stored procedure and I put myid as a parameter in my report in Reporting Services.
I don't know why it shows parameters in Reporting Services when I run the report from there, but when I try to create the subscription, it shows that I don't have any parameters.
Thanks, Iris
View 2 Replies
View Related
Aug 23, 2005
Hi, I have looked and loked for the answer to this question and made no progress. I want to install MSDE on one of our servers, however, when I went to install it, I found that there was another MSDE already installed and running (it was an agent running with our backup software Veritas). Is it alright to create another database and have 2 running simultaneous on the same data engine? Is there any type of limitations that I sould know about - such as number of allowed accesses at one time? Any help is greatly appreicated.
View 1 Replies
View Related
Aug 13, 2001
Hi all,
I'm trying to create a temporary table with one of the columns with a datetime datatype. Sql server 7.0 is giving me an error:
Error 195 date is not a recognized function name.
Example of my create table looks something like this:
create table #temp_table(column_one int, column_two(15,2), Column_three datetime)
View 2 Replies
View Related
Jul 11, 2015
Recently I've been stumbling with a way to properly produce a result that provides me a count of sales orders that fall in a range of sales order totals.
I want to take the Sales Order Total and then count how many times it falls into a specific bucket.
I've included the script where I've left with sample data so you can run in into a tempdb.
I hope to have the end result look like the below summary if you use my sample data.
Count Less Than 5K: 5
Count Greater Than 5K Less Than 10K: 0
Count Greater Than 10K Less Than 25K: 3
Count Greater Than 25K: 2
Here is the script to set up the tempdb
use tempdb
go
/*
drop table #salesinvoice;
drop table #salesinvoicedetail;
[Code] ....
Below is my query, I change it to perform a count on the summarized totals.
select
si.OrderID as OrderNum
,sum(case when sid.LineAmount < 5000 then 1 else 0 end) as LT5K
,sum(case when sid.LineAmount >=5000 and sid.LineAmount < 10000 then 1 else 0 end) as GT5kLT10k
,sum(case when sid.LineAmount >=10000 and sid.LineAmount < 25000 then 1 else 0 end) as GT10kLT25k
[Code] ....
Here are the order totals.
SI201 = 41450
SI202 = 11600
SI203 = 1210
SI204 = 16001
SI205 = 2750
SI206 = 12500
SI207 = 25450
SI208 = 4500
SI209 = 3850
SI210 = 2575
And the desired result would tell me the below summary. The final query can be column based. I just write this in rows for clarity.
Count Less Than 5K: 5
Count Greater Than 5K Less Than 10K: 0
Count Greater Than 10K Less Than 25K: 3
Count Greater Than 25K: 2
******/
View 3 Replies
View Related