SQL - How To - Minimum Number Of Steps
Jun 20, 2007
Hi. I have an 'Attendance' table like this:
PIN Year Category Days
1 2006 Authorized 1
1 2006 Available 2
1 2006 Personal 3
2 2006 Authorized 4
2 2006 Available 5
2 2006 Personal 6
3 2006 Authorized 7
3 2006 Available 8
3 2006 Personal 9
4 2006 Authorized 10
4 2006 Available 11
4 2006 Personal 12
1 2007 Authorized 13
1 2007 Available 14
1 2007 Personal 15
2 2007 Authorized 16
2 2007 Available 17
2 2007 Personal 18
3 2007 Authorized 19
3 2007 Available 20
3 2007 Personal 21
4 2007 Authorized 22
4 2007 Available 23
4 2007 Personal 24
I need to sum the days by PIN, Year and Category (that's easy...) AND
obtain a layout like this:
PIN Auth 2006 Avail 2006 Pers 2006 Auth
2007 Avail 2007 Pers 2007
1 1 2
3 13 14 15
2 4 5
6 16 17 18
3 7 8
9 19 20 21
4 10 11
12 22 23 24
How can I do this by queries without writing too many intermediate
steps ?
What I have done is this (5 queries, 2, 3, and 4 building on top of
1,
and 5 building on 2, 3, 4).
1 = Table1_Crosstab:
TRANSFORM Sum(Table1.Days) AS SumOfDays
SELECT Table1.PIN, Table1.Year
FROM Table1
GROUP BY Table1.PIN, Table1.Year
PIVOT Table1.Category;
Then, based on that,
2 = Authorized:
TRANSFORM First([1 = Table1_Crosstab].Authorized) AS
FirstOfAuthorized
SELECT [1 = Table1_Crosstab].PIN
FROM [1 = Table1_Crosstab]
GROUP BY [1 = Table1_Crosstab].PIN
PIVOT [1 = Table1_Crosstab].Year;
3 = Available:
TRANSFORM First([1 = Table1_Crosstab].Available) AS FirstOfAvailable
SELECT [1 = Table1_Crosstab].PIN
FROM [1 = Table1_Crosstab]
GROUP BY [1 = Table1_Crosstab].PIN
PIVOT [1 = Table1_Crosstab].Year;
and
4 = Personal:
TRANSFORM First([1 = Table1_Crosstab].Personal) AS FirstOfPersonal
SELECT [1 = Table1_Crosstab].PIN
FROM [1 = Table1_Crosstab]
GROUP BY [1 = Table1_Crosstab].PIN
PIVOT [1 = Table1_Crosstab].Year;
and finally
5 = All
SELECT [2 = Authorized].PIN, [2 = Authorized].[2006] AS [Auth 2006],
[3 = Available].[2006] AS [Avail 2006], [4 = Personal].[2006] AS
[Pers
2006], [2 = Authorized].[2007] AS [Auth 2007], [3 = Available].[2007]
AS [Avail 2007], [4 = Personal].[2007] AS [Pers 2007]
FROM ([2 = Authorized] INNER JOIN [3 = Available] ON [2 =
Authorized].PIN = [3 = Available].PIN) INNER JOIN [4 = Personal] ON
[3
= Available].PIN = [4 = Personal].PIN;
It works, but... I am sure that this is an awkward way of doing it.
Is
there any other, more elegant, way, please ? Besides, what if I had
not 3, but 15 categories, for example ????
Thanks a lot for your time reading this, Alex
View 4 Replies
ADVERTISEMENT
Jun 20, 2002
Hello,
Can anybody tell me how many steps it's possible to put in one job.
The reason I ask is that we have a job that has over 500 steps (import data from Excel file into SQl table) and every time it runs we have different steps failures.
Does fact, that excel file was dropped and recreated, change DTS Id ?
Thank you in advance
View 4 Replies
View Related
Dec 14, 2014
I got this ERD and I have 2 questions about it:
What is the minimum number of times that R2 can appear in the connection? and what is the maximum?
A=5
B=5
C1=1
C2=2
View 1 Replies
View Related
Jun 6, 2001
Hi,
I have two job J1 and J2, each one has 10 steps. Now I want J2 to be the 11th step of J1 and I did not want manually type all the steps of J2 to be 11-20 step of J2. Is there an easy way through TSQL to do this ?
sp_add_jobstep only works when the step is OS command or a script but not a job
View 2 Replies
View Related
Sep 17, 2007
In my table I have values like (2,3). I want to get the minimum value from the column
View 12 Replies
View Related
Apr 26, 2007
Hi All,How do I set just enough permissions on a database so that a developer cancreate new objects and modify them without giving him administratorprivilege. At the moment the db objects are dbo and execute permissions aregranted to indevidual through a schema.GRANT EXECUTE ON [dbo].[My_Prcsedure] TO [MySchema]Thanks
View 2 Replies
View Related
Dec 20, 2004
i need to create a dynamic field, which returns the minimum value of 2 fields.
A B C(i need)
500 600 500
350 250 250
825 950 825
select A,B,min(A,B) as C from MyTable
i know this query is wrong,
pls help me to solve this problem
RGDS
BAHA
View 4 Replies
View Related
Mar 15, 2007
How can I find the minimum value of column?
Select salonuid, avg(LPPA),[Find the minimum](LPPA) from kpi.dbo.employee_data group by salonuid
The Yak Village Idiot
View 2 Replies
View Related
May 5, 2006
How to find the minimum value from time Timestamp column ?
I want get the eralier timestamp vlaues from the avaliable list
when iam using Aggregate transformation ..its again giving all the list of vlaues
Thanks
Niru
View 4 Replies
View Related
Dec 6, 2004
Hallo Cracks,
what I try is a little bit heavy, maybe, but I only miss the minimum/maximum fuction - or I didn´t found it; not here in the Forum and also not in the onlinehelp of the SQL Server.
What I try to do:
I have 2 columns in my table; a start- and an end-date. For this period of time between end and start i have to calculate the days for the years. Here my thoughts (for the current year):
Is the startdate <= 31.12.2004 and the enddate >= 1.1.2004 i have to calculate die datediff between max(1.1.2004/startdate) and min(31.12.2004/enddate)
like this sqlstatement:
SELECT CASE WHEN dbo.Phases.phasenstart <= CAST(CAST(YEAR(GETDATE()) AS
varchar) + '-31-12' AS smalldatetime) AND dbo.Phases.phasenabschlussist >=
CAST(CAST(YEAR(GETDATE()) AS varchar) + '-01-01' AS smalldatetime)
THEN 365 ELSE 0 END AS Expr2,
FROM dbo.Phases
WHERE (phasenstart IS NOT NULL) AND (phasenabschlussist IS NOT NULL)
instead of 365 there must be the above calculation. Is start=3.1.2003 and end=30.1.2004 I expect as result only the 30 days in 2004.
thanks in advance and kind regards :-)
Cappu
View 2 Replies
View Related
Nov 12, 2014
I'm looking at the following Records:
cust_no item_no start_dt end_dt price
1060 2931 2011-02-06 9999-12-31 1.23
1060 2931 2011-04-18 9999-12-31 2.00
I want to be able to pull the records with the earliest date 2011-02-06 ...
There were other records with this same customer and item number. I used this script to return the two above.
select *
from price
where end_dt > getdate()
Now I need to add something so it only returns the record with the earliest date. I'm going to run this on a table that has many customer and item combinations.
View 3 Replies
View Related
Apr 13, 2015
I want the minimum of two values to be display like below without using the case
MIN(3.00,4.00)
output:
3.00
View 2 Replies
View Related
Jul 27, 2006
Hello,I need to select the minimum between the result of a function and anumber, but i can't find a smart way. By now I'm doing like thefollowing, but I think is very expensive because it evaluates thefunction twice:select case when (myfunction())<100 then (myfunction()) else 100 endAny idea is appreciated.Thank youRegards--elimina carraro per rispondere via email
View 4 Replies
View Related
Jun 6, 2006
Hi,
l've a series of day which record the date of an event. l would like to count the # of continuous days for the event. In this case, it would be 14/5, 15/5, 16/5, 17/5, 18/5, 19/5 and 20/5. Any idea to do this in SQL?
Date
-----
20/5
19/5
18/5
17/5
16/5
15/5
14/5
09/5
07/5
06/5
05/5
View 7 Replies
View Related
Aug 21, 2006
hello
i have one doubt.can anybody clarigy it.
every time i am doing my database shrinking manually.
what i am asking i find out every time when i shrink my database that sql is showing minimum size of database to shrink.how can its getting minimum size
but i need to find out how to get minimum size of particular database programatically.
thanx
View 3 Replies
View Related
Oct 27, 2000
What is the minimum installation on a user's PC to enable them to run a DTS package using the DTSRUN utility in a DOS bat file. The user currently does not have the mssql7inn directory on their PC. I don't want to install all of the components of SQL Server 7.0 on their PC, i.e., Query Analyzer, Enterprise Manager, etc. Does the server referenced in the DTSRUN command line need to be registered on their PC?
View 1 Replies
View Related
Sep 16, 2012
I am trying to get the minimum and maximum values from a field in SQL Server 2008 Express, but I cannot even get started because I keep getting this error that I cannot figure out.
View 6 Replies
View Related
Jan 19, 2014
I need to capture records with the minimum claim ID when the prov, diag, and the billed are the same, but the claim id and check id are different.
EXAMPLE:
CLAIM DOS PROV DIAG BILLED CHECK#
2001 02/05/11 500 252.5 30.00 35
2015 02/05/11 500 252.5 30.00 56
On this example, I would need to capture the record with Claims ID 2001 and exclude the other.
View 4 Replies
View Related
Sep 3, 2013
I receive the following result set from TableA (In Time)
7/9/2013 9:27:00.000 AM
7/9/2013 10:24:00.000 AM
7/9/2013 11:25:00.000 AM
7/9/2013 1:23:00.000 PM
7/10/2013 7:27:00.000 AM
Then we receive the following result from TableB (Out Time)
7/9/2013 9:30:00.000 AM
7/9/2013 10:29:00.000 AM
7/9/2013 1:37:00.000 PM
[NULL]
[NULL]
We may not always get Out Times in TableB so I want to merge these into one table to have the In Time and Out Time in separate columns in that one table. In this example with the red type those should be In Time and Out Time for mapped unique identifiers from each table and yet the purple color coded example would have an In Time of 11:25 AM and the Out Time would remain as NULL.
I am using this block of code but is not working the way I want it to because the 11:25am In Time is getting mapped to the 1:37pm Out Time.
and out_time = (select min (out_time)
FROM tableB WHERE
tableB.record# = tableA.record#
and tableB.loc_id = tableA.loc_id
GROUP BY tableB.record#, tableB.loc_id )
It seems I need to focus on the minimum datediff for each record line but can't figure that part out.
View 2 Replies
View Related
Jun 6, 2007
Off of the MSDN SQL Server 2005 Enterprise Edition, what is the MSI I should use to install SQL Server 2005.
I have to Upload all files to a server, and this is going to be painfully slow. Can anyone tell me what the minimum is to upload and install SQL Server Enterprise (not Express)?
(For 32 and 64 bit non-Itanium machines)
View 7 Replies
View Related
Dec 10, 2007
I have went thru template.ini . it seems very complicated. i only want to innstall sql express edition
with instancename, security mode and sapwd. ihave givem it in template.ini
[Options]
SECURITYMODE=MIXED
INSTANCENAME=DCS123
SQLACCOUNT=sa
SQLPASSWORD=changeme
with cmd line parameter d:sql2k5setup.exe /qb / settings c: emplates.ini
it made an error message invalid ini file make sure the file exists , have access and has the correct entries.
i tries to input all details in command line.
d:sql2k5setup.exe SECURITYMODE=MIXED INSTANCENAME=DCS123 SQLPASSWORD=changeme
it also failed to work.
we cant input more details like user account etc..
kindly help us in this rgards
View 4 Replies
View Related
Oct 7, 2007
Hi,
I have a column set to varchar(12) so I can ensure that the length of the string entered will never be more than 12 characters but I want to limit the string to a minimum of 8 characters, so I end up with a string that is from 8-12 characters long. How do I ensure the minimum length of 8 characters? I'm using SQL Server 2005 if that helps. I tried adding a check constraint like so:
DATALENGTH(UserName) >= 8
But I keep getting an error when I save the table, so any help would be very much appreciated.
Thanks
View 3 Replies
View Related
Jan 7, 2008
Hi All:
I hope I'm in the correct forum for this question. If I'm not, forgive me and point me in the proper direction.
I have SQL Server 2000 databases that I am trying to secure. To that end I've deleted the guest account from all but the master and tempdb databases.
Within the master db I've denied access of any "flavor" to all objects but spt_values, syscharsets, sp_MSSQLDMO80_version, and sp_MSdbuserpriv (only because I've discovered they are necessary).
Can anyone tell me where I might find the absolute minimum permissions configuration for the guest account in master?
I have no third party vendor software accessing my SQL Server 2000 databases. The thought of
Demographics:
SQL Server 2000 sp4 running on Windows 2003 Server with the current service packs.
Any help is greatly appreciated.
caeriel
View 1 Replies
View Related
May 8, 2007
I am trying to understand constraints and minimum cardinality.
In a relationship between 2 tables, t1 and t2, with a parent to child relationship of
1 to 1 or more
how is the minimum cardinality enforced?
If both sides of the relationship require at least one occurrence, how would the insert be done? How can you insert into table t1 when it has a constraint that there must be an occurrence in table t2, or vice versa?
Any help in understanding this is greatly appreciated!
View 4 Replies
View Related
Jul 19, 2015
I have a database for which I need the permissions to execute stored procedures, perform CRUD operations on tables, execute functions and SQL jobs. What should be the SQL command if I am to create a user for this database who will have the most minimum privileges to carry out these activities?
View 4 Replies
View Related
May 21, 2007
I want to display a chart with a minimum y-axis of -10%. When use the value -0.10 the result is a minimum of -100%. Is this a bug?
-Jeroen
View 2 Replies
View Related
Jan 17, 2008
Hi,
I have a client application that creates a COM object using the program ID 'SQLOLEDB enumerator' to get an ISourcesRowset. Once I retrieve the ISourcesRowset, I call ISourcesRowset.GetSourcesRowset to obtain a list of available servers.
This works if the client computer (the one running the application) also has SQL Server (or SQL Express) installed. But on a clean computer after installing SQLNCLI.MSI, the call to GetSourcesRowset returns an error 80004005.
My question is, what do I need to install on my client's machines so I can retrieve available servers using this method? Is there another MSI that needs to be installed? Do I need to install SQL Express Client_Components? Or is there something else?
Thanks in advance for any information you can provide.
-Eric Harmon
View 1 Replies
View Related
Jul 24, 2000
Hi,
I'm using SQL Server 7.0. I have a job which runs DTS packages (1 package per step). When a task fails within my DTS package, I'd like an error returned for that step in the job thus stopping the job and not starting up the next step (DTS package) in the job. As it stands right now, if a task fails within the DTS package, that step in the job still returns a successful completion. Has anyone seen this before and is there something I can do to get the DTS to send a failure for that step in the job?
Thanks in advance,
Darrin
View 1 Replies
View Related
Jan 12, 2007
I am going to be moving multiple databases to a new server. Everything should go smooth, but I need to change a lot of the DTS packages that reference the old servername and replace it with the databases DNS record.
Is there an easy way to get a list of which dts reference the old server explicitly (not using database DNS)?
Thanks.
View 7 Replies
View Related
Oct 13, 2014
I have a table with data like the following:
ClientID InvoiceDate
1 2012-01-01
1 2013-01-01
2 2012-01-01
2 2013-01-01
3 2012-01-01
3 2013-01-01
I would like to return a distinct ClientID and also the minimum InvoiceDate for that ClientID, so that the data looks like this:
ClientID InvoiceDate
1 2012-01-01
2 2012-01-01
3 2012-01-01
View 1 Replies
View Related
Aug 8, 2006
Hi everyone;
I'm just getting started. I'm on Window 2000 pro with service pack 4 etc...
I installed "C#" and "Microsoft Visual Web Developer 2005 Express Edition" -thats fine.
I then installed "Microsoft SQL Server" (SQLEXPR.EXE) it was good until it did a check:
Everything checked and passed fine except for the 2nd to last one:
- Minimum MDAC Version Requirement (Error)
Messages
* Minimum MDAC Version Requirement
* The system does not have the required version of Microsoft Data Access Components (MDAC) for this SQL Server release. For details, see Hardware and Software Requirements for Installing SQL Server 2005 in Microsoft SQL Server Books Online.
- Edition Change Check (Success)
Messages
* Edition Change Check
* Check Passed
-----------------------------------------------------------------
So I was wondering where did I go wrong. I have lots of hard drive space too.
CPU is 1.80GHz - with 523,056 KB RAM
I did some research but there seems to be 100's of pages.
View 4 Replies
View Related
May 7, 2007
I have a report that calculates mean, min, max, stddev of somer exercises for a class (pushups, situps, trunk lifts, etc). I also have to calculate those for the 1-mile run time (ex: data -- 7:56, 6:35, 9:45 ( in minuteseconds). Obviously the standard Avg(), Min(), Max(), StdDev() functions won't work for time. So I put in some custom code to convert the time to seconds so I can use the standard functions on the seconds and also code to convert that answer back to minuteseconds. Max() works, but for example when I try to calculate the min(), it includes nulls from the dataset as zeros (not every student has to do the mile run). So the min is always 0. How can I exclude nulls from being calculated. The min() function excludes nulls so it returns the correct min() on integer data. What else can I do?
View 3 Replies
View Related
Aug 3, 2015
My sql gives me the results as shown in #TEMTAB Table.some times Mitem_id is repeated for the same Group_id,SGroup_id with different item_id
ex: SQ322,SQ323,SQ324,SQ325 are repeated here.
CREATE TABLE #TEMTAB
(Group_id int, SGroup_id int, item_id int, Mitem_id varchar(10)
,YN varchar(2),value varchar(8),reason varchar(20))
[code]...
View 8 Replies
View Related