I've always user over with partitioning however recently I am looking at some other code and they have calculating percentages using over. I'm at a lost on why you would do this.
Example would be
CAST(TABLE1.UNIT AS DECIMAL (6,2)) / SUM(TABLE2.UNIT) OVER () AS UNIT_%
I have a query which provides the total number of each of 2 invoice flags per month, starting 1st Feb this year. I also need a percentage calculated for each of the 2 flags by month. However, it is showing the totals correctly for each of the flags by month, but the percentage is using the total of both flags for all months, and so it is wrong if I only want to look at one month. The query is as follows along with a sample output including % which are incorrect.
How can I correct this so that it shows the right % for each of the flags for each month?
Select sk.Period Period, sk.[Invoice Flag], count(*) * 100.0 / Sum(count(*)) Over () Percentage, count(*) Total1 From (Select wh.worknumber [Work Order],
[code].....
Output at present:
Period Invoice Flag Percentage Total1 --------------------------------- ------------------------------- --------------------------------------- ----------- 2015-02 Invoiced after 7 days 5.704697986577 136 2015-03 Invoiced after 7 days 2.097315436241 50 2015-02 Invoiced with Customer Approval 59.563758389261 1420 2015-03 Invoiced with Customer Approval 32.634228187919 778
So, in the [Execute SQL Task], it runs a stored procedure, which returns a 0 or 1 value, which is bound to the variable @IsCurrent. The variable then gets evaluated in the "expression." If @IsCurrent is 0, execution continues to the [Script Task]. That part works fine.
The problem is occurring in the [Script Task] portion. All the Script Task does is "sleep" for 3 minutes. Here is an excerpt of the code:
If CInt(Dts.Variables("sleepCounter").Value) = 20 Then
Dts.TaskResult = Dts.Results.Failure
Exit Sub
End If
So, as you can see, if "sleepCounter" = 20, it fails the task, which should then fail the package, right??
However, the package keeps running, even after sleepCounter has exceeded 20. The MaximumErrorCount on the For Loop container is set to 20 also. So after 20 failures, this package should fail, but it isn't!
According to BOL the ForceExecutionResult property can be used to imitate real-time failure (http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.dtsforcedexecresult.aspx).
However, I've just done a very simple test and this appears to not be the case. Here's the repro:
Start a new package Drag on a Sequence Container Set the sequence container property ForceExecutionResult='Failure'
When you run the package the sequence container will complete successfully. As far as I can see its not supposed to.
I€™m importing a Flat file (delimited text) into a sql server database table and trying to trap any import errors in another output Flat file.
I create a Flat File Source task. After tweaking the task, the Source €œError Output€? tab shows all the input columns and all €œError€? and €œTruncation€? values are set to €œRedirect row€?
Next I add a €œSQL Server Destination€? task and connect the Source green arrow to it.
Finally I add a Flat File Destination task (error Output task), connect the Source red arrow to it, click €œOK€? in the €œConfigure Error Output€?, and finally add a connection manager to the Error output task. When I look at the Mappings tab of the Error Output file it shows only three available input columns: €œFlat File Error Output Column€?, ErrorCode, and ErrorColumn
I€™m not sure where they came from but that info is not very useful to me. I want to know which line the error occurred on as well as the bad column(s). If nothing else, I need to see at least the actual row that was bad. How can I get that information?
i have the percenatge that 10%...now i want to check that whether this 10 % is in between the frompercentage and topercentage..if it is there i want to return the the scale value..how can i do this in sql.
i know comparing when it is integer using where and and operator..but i dont know how use if it has the percentages.
most my fields that I am interested in getting percentage values for have to be counted first.... I am having problems converting the counted values to percentages. I don't think I am doing it right...
I would greatly appreciate an example of a very simple matrix table with a counted value that displays percentages. I have found examples online but are part of a much more complex table and I can't seem to get thier formating to work on mine.
Hello,I'm trying to something that just works in Oracle, but does not in SqlServer.How can I get the percentage of two counts to be returned on each rowof the query?select count(sid), /* all not the not null */count(*),(count(sid) /count(*) ) as percent_not_null,4 as four,(3/4) as three_over_fourfrom dbo.sysusers7082040Incredibly, it changes even 3/4 into a zero!For efficiency, I want the percentage returned in the query.And to not use variables and coding. Efficiency,both of the server, and of my time.Note: I am using dbo.sysusers as an EXAMPLE only. My realquery will be on user defined application tables.What is the solution please?
I have two values and I want to express a third derived value as apercentage of the other two values. I thought it would be a simpledivision of the first two numbers and then a multiplication by 100 togive me a percentage, but all I get is 0.Here is my select statement,SELECT dbo.Eligble.GRADETotal,dbo.nil1234_Faculties_Totals.FACTotal,dbo.nil1234_Faculties_Totals.FACTotal /dbo.Eligble.GRADETotal * 100 AS [PERCENT]FROM dbo.Eligble CROSS JOINdbo.nil1234_Faculties_TotalsCan anyone point out where I'm going wrong here?Thanks in advance
Trying to create a dataset for a report. I need to bring back percentage in the result set. The fields that I am using to get the percentage have valid data but the result field is 0.00%. Is there reason I cant bring back a percentage field?
Code: SELECT JobNum, Mailed, LT_7, BT_6_10, GT_10, Format([LT_7]/[Mailed], 'p') AS PctScaned1, Format([BT_6_10]/[Mailed], 'p') AS PctScaned2, Format([GT_10]/[Mailed], 'p') AS PctScaned3,
SELECT DISTINCT CASE WHEN SM.SERVICE_TYPE_N = 1 THEN 'LABORATORY' WHEN SM.SERVICE_TYPE_N = 2 THEN 'PODIATRY' WHEN SM.SERVICE_TYPE_N = 3 THEN 'ADMINISTRATION' WHEN SM.SERVICE_TYPE_N = 4 THEN 'DIET' WHEN SM.SERVICE_TYPE_N = 5 THEN 'DENTAL'
[Code] ....
In the above query i need to calculate 100%,30% and percentage other than 100 and 30 and show them in separate columns how to do that?
1)ROUND(SUM(BM.CONCESSION_AMOUNT_M),2)AS [100_PERCENT] WHERE BM.BILL_AMOUNT_M=BM.CONCESSION_AMOUNT_M
2)ROUND(SUM(BM.CONCESSION_AMOUNT_M),2)AS [30_PERCENT] WHERE AND BM.CONCESSION_AMOUNT_M=BM.BILL_AMOUNT_M * 0.30
3) ROUND(SUM(BM.CONCESSION_AMOUNT_M),2)AS [OTHER_CONCESSION_PERCENT] WHERE BM.CONCESSION_AMOUNT_M between BM.BILL_AMOUNT_M*0.001 and BM.BILL_AMOUNT_M*0.299 OR BM.CONCESSION_AMOUNT_M between BM.BILL_AMOUNT_M*0.301 and BM.BILL_AMOUNT_M*0.999
I have two tables that look like this (below). One tells me the name of my product, the Amazon Category it is in & the amount that I want to sell it for. The other tells me the Category & the fee for that category. So far so good. Though it gets tricky in the sense that some categories have two tiers. So in Electronics, the fee for $0.00 - $100.00 is 15%. But from $100 and up it is 8%.
Since it has two columns & both of the new columns pertain to the fee of my product, I can't figure out how to use both at once. For my $599.99 example it would be ($100 * 0.15) + ($499.99 * 0.08) = $55.00. Would I pivot the data? If not, how would I group it to be considered together?
I've created a report that has cells in it that I want to be formatted as percentages. I set the format code in the cell properties to "P1" and everything appears to work fine until I export to Excel. Some cells show up with only one digit after the decimal and some show up with two digits after the decimal. I looked at the formatting in Excel (right click, Format Cells...) and it is set to "[$-1010409]#,##0.0#%". I don't have the first clue what that is "supposed" to do but what it does is this:
If I enter 100.00 in the cell it shows up as 100.0%. Expected If I enter 100.10 in the cell it shows up as 100.1%. Expected If I enter 100.15 in the cell it is displayed as 100.15%. Not expected
I have formatted the report to only show one digit after the decimal, but RS exports to Excel with some funky formatting that sometimes shows one digit and sometimes two digits after the decimal. Why wouldn't it simply format the cell as a percent? How can I get it to only show a single digit after the decimal?
This is Excel 2007 but Excel 2003 has the same behavior.
I'm banging my head against the wall. It's probably pretty simple so here goes...
I have a form that supposed to add records to a table on the database. I'm pretty sure I have the dataAdapter and Dataset set right but when I add a record, it complains that the primary key can’t be null. I’ve tried different things, including removing those fields and variables from the stored Proc, changing the Identity Properties of the Table, changing the AutoIncrement settings on the Dataset for that field, but all give me different errors. Nothing actually makes it work. This database has many records in it and the Primary key is a decimal field that starts at 5, then next was 10, then 28, then it started getting consecutive after 110. (111, 112, 113, etc.) (I'm porting over an old database to a new web site, so I'm somewhat contrained by the database.)
I guess my question is for adding records in to a database that has a primary unique key constraint. Certainly this is a pretty common thing. Obviously I do not want users to enter that in themselves, I thought it should simply autocreate/autonumber. So what is the best procedure and gotcha’s I need to watch out for?
if i have the following code, how do i know if the transaction was actually successful, so basically where in this code can i write TRANSACTION SUCCESFUL?
try { //Open up the connection conn.Open(); //Setup the Transaction trans = conn.BeginTransaction();
//First query in transaction pre_query = "Delete from Menu where spec_name=" + "'" + spec_name_array[i].Text.ToString() + "'" ;
//Second query in transaction query = "INSERT into Menu VALUES ('" + Calendar1.SelectedDate +"','" + spec_name_array[i].Text.ToString() +"','" + spec_desc_array[i].Text.ToString() +"','" +spec_price_array[i].Text.ToString() +"',1)"; SqlCommand comm = new SqlCommand(pre_query,conn); //Setup the command to handle transaction comm.Transaction = trans; //Execute first query comm.ExecuteNonQuery(); //Add in second query comm.CommandText = query; //Execute second query comm.ExecuteNonQuery(); trans.Commit(); } catch(SqlException ex) { com_label.Text = "Submission Not complete, did you forget the date or something else?"; //Undo all queries trans.Rollback(); } finally { conn.Close(); }
This may not be the right place for this post...but my head is hurting and I can't think right now.
I have a SQL table of users. Each record has a required 'Birthdate' field. I'd like to order this by the days left till the give birthday, keeping in mind that the year may be 1980 or their birthday might have been 2 weeks ago.
I have written 2 custom connection mgr€™s. One connects the data from an oracle source One connects so I can put the data on a sql server. These both work well and it makes it a lot easier across development, test, production.
But now I would like a good way to do this
I have 10 tables to copy from oracle. The only difference is just the name of the table.
If I have a 64 bit version of SQL 2005 installed, will "select @@version" indicate it is a 64 bit version? If not, how do I determine such? Thanks in advance.
I have a column in my report that i want to show percentage change from the previous year to this year. So i enter all kinds of different type of formats for the formula, and keep getting the wrong answers or error messeges. Here's what i have tried recently:
hi, I have this simple sql query - it should be pretty obvious what I'm trying to achieve but this syntax isn't accepted on SQL 2005, any suggestions? SELECT Name FROM Users WHERE UsersID IN (EXEC dbo.ReturnDataByModule 'Groups',1200)
Ok - I am still a bit weak on SQL. My understanding of FK relationships in a database are to reinforce the data integrity - Correct? For example, does it make sure that the id given for SiteID does indeed exists. Can it link tables like JOIN in select statements? If not, is there any gains by creating them, such as performance?
scenario I have 2 tables one is called "Site" which contains columns ID, Address1, Address2,City,StateID,ZipCode and the second table is called "State" which contains columns ID,Name,Abbreviation. I am looking to make a view that contains all the sites with the state inner joined on stateid to make my all my other queries easier. That is so I can just select from the view without having to do the inner join on the state. My question is when a new record is added to table Site do I have "recreate"/update the view?