Adding To Outputs Together To Retrieve The Top(10) - Is It Possible??

Sep 24, 2007

Hi There,

I have been struggling day and night with the creation of a store procedure due to not being able to retieve the rows I need for SUM and AVG functions.

I have two tables ('actions' & 'incident_types') which both have a score value for each record. In my database, I have reports that contain both action codes and incident_type codes based on a personnel_code.

In simple terms I'm trying to do the following:-
For all reports, find each personnel member and thier attached incident_types and action codes and then, for each score from the actions and incident_types tables, create the SUM of the 'combined' scores.

I have successfully retrieved the output for the scores individually but I need the TOP(10) of the combined output.....

I'm currently using to seperate queries as follows :--


--This gives me the incident type output...... Creating the 'Volume' column which is the total Score for incidetn_types
SELECT Top (@Number) Personnel_details.personnel_code, Personnel_details.personnel_forename, Personnel_details.personnel_Surname, sum(incident_types.type_score) as 'Volume', avg(incident_types.type_score) as 'Average' INTO 'Incident_Scores' from Report_header

JOIN incident_types on incident_types.type_code = report_header.report_incident_Code

JOIN report_basedon on report_basedon.report_code = report_header.report_code

JOIN personnel_details on personnel_details.personnel_code = report_basedon.personnel_code

WHERE (report_header.report_date >= @fromDate and report_header.report_date <= @toDate)

AND (report_header.report_time >= @fromTime and report_header.report_time <= @toTime)

AND report_basedon.personnel_code <> 0

AND report_header.record_status=@recordStatus

group by Personnel_details.personnel_code, Personnel_details.personnel_forename, Personnel_details.personnel_Surname



-- I then use the following to get the total of all action scores, again in the 'Volume' column
SELECT Top (@Number) Personnel_details.personnel_code, Personnel_details.personnel_forename, Personnel_details.personnel_Surname, sum(actions.action_score) as 'Volume', AVG(actions.action_score) as 'Average' from profile

JOIN actions on actions.action_code = profile.action_code

JOIN report_header on report_header.report_code = profile.incident_ID

JOIN personnel_details on personnel_details.personnel_code = profile.personnel_code

WHERE (report_header.report_date >= @fromDate and report_header.report_date <= @toDate)

AND (report_header.report_time >= @fromTime and report_header.report_time <= @toTime)

AND personnel_details.personnel_code <> 0

AND report_header.record_status=@recordStatus

AND profile.record_status=@recordStatus

group by Personnel_details.personnel_code, Personnel_details.personnel_forename, Personnel_details.personnel_Surname

So my question is - How can I get the sum(incident_types.type_score) + sum(actions.action_score) and then get the TOP(10) rows?


Is it possible to output these 2 result to a new table and then join the new tables?

Thanks for any assistance, this is really draining me at the moment..... :-/

View 8 Replies


ADVERTISEMENT

Retrieve Id After Adding A New Record

May 13, 2005

How do I retrieve the id of the record after I INSERT it?

View 4 Replies View Related

Emailing The Outputs

Apr 13, 2000

I need to send the output of a report generated, automatically through email as an attachment to some customer.Is it possible?Can anyone help?

View 1 Replies View Related

Errorlog Monitoring && Job Outputs

Nov 2, 2004

Considering email is setup, how would you send emails by scanning errorlog for any issues. Also, how to send program outputs using email.

Thanks

View 4 Replies View Related

Synchronous Vs Asynchronous Outputs

Jan 3, 2008

Can someone please clarify:

If you have a data file, and you only want CERTAIN rows to pass to the destination, ie) a table

and you are using a script task to accomplish this,

is this a synchronous or asynchronous transformation?

Q. And how do you assign the values to the output? Do you have to create output columns, or not?

I am very very confused right now. I can't seem to find a decent answer to what is a very basic question either in my SSIS book or in the documenation. Perhaps it is so basic, that the question doesn't seem valid? I don't know. But I just don't understand this at all.

Thank you

View 9 Replies View Related

Question Regarding Stored Procedure????OUTPUTS

Mar 19, 2004

I have a stored procedure that I just need to return the output to my program.It is a Select All type statement.I will post my vb code that works when I use both inputs and outputs but not for all output procedure...I dont get it.
Here is the Stored Procedure.....


CREATE procedure dbo.IDXAppt_Settings_NET
(
@SQLADD nvarchar(15)Output,
@SQLDatabase nvarchar(20)Output,
@SQLLogin nvarchar(20)Output,
@SQLPass nvarchar(20)Output
)
as
select
@SQLADD=SQLAddress,
@SQLDatabase=SQLDatabase,
@SQLLogin=SQLLogin,
@SQLPass=SQLPassword

from
Clinic_Settings



GO

Here is the Vb.Net Code........
To retrieve the elements that does not give me an error just gives me no data....


Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim consql As New SqlConnection("server=myserver,database=APPOINTMENTS;uid=webtest;pwd=webtest")
Dim cmdsql As New SqlCommand

Dim parmSQLAddress As SqlParameter
Dim parmDatabase As SqlParameter
Dim parmLogin As SqlParameter
Dim parmSqlPass As SqlParameter

Dim strtest As String
Dim db As String
Dim login As String
Dim pass As String

cmdsql = New SqlCommand("Appt_Settings_NET", consql)
cmdsql.CommandType = CommandType.StoredProcedure
parmDatabase = cmdsql.Parameters.Add("@SQLData", SqlDbType.NVarChar)
parmDatabase.Size = 20
parmDatabase.Direction = ParameterDirection.Output
db = cmdsql.Parameters("@SQLData").Value

parmLogin = cmdsql.Parameters.Add("@SQLLogin", SqlDbType.NVarChar)
parmLogin.Size = 20
parmLogin.Direction = ParameterDirection.Output
login = cmdsql.Parameters("@SQLLogin").Value

parmSqlPass = cmdsql.Parameters.Add("@SQLPass", SqlDbType.NVarChar)
parmSqlPass.Size = 20
parmSqlPass.Direction = ParameterDirection.Output
pass = cmdsql.Parameters("@SQLPass").Value





parmSQLAddress = cmdsql.Parameters.Add("@SQLADD", SqlDbType.NVarChar)
parmSQLAddress.Size = 15
parmSQLAddress.Direction = ParameterDirection.Output
strtest = cmdsql.Parameters("@SQLADD").Value
consql.Open()
cmdsql.ExecuteNonQuery()

Label1.Text = strtest
End Sub

View 2 Replies View Related

Stored Procedure Outputs And Return Value. Please Help!

Oct 12, 2004

Hi everyone!
I have an stordprocedure that returns a resultset , an output value and an return value.
I invoked this procedure using an sqlcommand object ( by ExecudeReader method ) and I filled a SqlDataReader object by the resultset.
dr = cmd.ExecudeReader();
but I cant reach its output variable and its return value (cmd.parameters["@ret"].value).
an exception raises : object refrence error!
what is wrong in this approach ?
please help me.

View 3 Replies View Related

How To Handle Large Outputs From RDBMS

Nov 30, 2014

Obviously Excel is the tool of choice for most people but with it's limited ability to leverage RAM (32 bit) and it's limitation with rows at just over 1 million what other choices do we have for viewing data?

My bosses boss created several OLAP universes and they seems to fly a lot fast than regular relational database. This still doesn't work with the fact the data can't be worked with unless you have a strong front end that can handle processing all those rows.

View 9 Replies View Related

Transact SQL :: Two Different Outputs From Single Query?

Jul 22, 2015

I have a table with email addresses and CC_Flag.

Email     | CC_Flag
xxxx           0
yyyy           1
zzzz           1

Using Task SQL, I am trying to pass these email addresses to two separate variables - To_field, Cc_field on basis of the CC_Flag. Is it possible to fill two variables from a single SQl Task.

View 8 Replies View Related

Multicast Does Not Send Data To All Outputs

Apr 11, 2007

Hello, I am using a multicast with 5 outputs, I attempting to pass about four thousand rows to different destinations. However, upon execution only two of the outputs send the rows to the destination. After deleting the multicast and reinserting it, different destinations received the data. The number of destinations is also not consistant, sometimes 3 work and sometimes only 1 works.
Thank you.

View 14 Replies View Related

Help, How To Write 2 Outputs To One Text File??

Mar 13, 2007

Hi,

SQL Server 2005, sp2

What I am trying to do is very simple. I just want to run 2 stored procedures, then have the output from both sp's written to a single file.

I created a Data Flow task, then put 2 OLE DB Source adapters in the Data Flow task, one for each stored procedure.

Next, I dropped a Flat File destination object onto the page. However, I can only connect ONE arrow from one of the OLE DB Source adapters to the Flat File destination. It won't let me connect both.

What am I doing wrong here? How can I accomplish what I am trying to do here?

Thanks much

View 3 Replies View Related

Script Component With Multiple Outputs

Sep 25, 2006

Hi,

I wonder if someone might be able to help me with scripting a script component. I'd like to include error redirection of rows within my script.

If the conversion of any of my inputs fail i'd like to catch the error and then just output all values to another output path. The output path will just take the input values without converting them from string data types and output them to an error table.

In the script i imagine i would use try catch statements and if it fails then set the output. I am not entirely sue as to how to go about switching between outputs though.

Any help on this matter would be greatfully recieved.

Cheers,

Grant

View 4 Replies View Related

Asynchronous Outputs On Script Component Best Practice

Mar 14, 2006

If you have an output that is not synchronous with the input what is the best way of processing the data.

I am currently using a generic queue, and a custom class. I am creating an instance of the class in the ProcessINputRow and then adding it to the Queue.

The CreateNewOutputRows Dequeues the class instances and creates buffer rows.

Is there a better solution?

View 2 Replies View Related

Need Example Of Source Component With Multiple Non-Error Outputs

Aug 21, 2007

Can someone please point me to one or more examples of a Source component that has two or more outputs?

I wrote a source, which works with a single output, but after adding a second output, I see no rows there. I've single-stepped the code in the debugger, and it looks like it should be adding rows to the second output, but the downstream component never sees any.

Thanks.

View 7 Replies View Related

Asynchronous Outputs Technet Example Wrong Or Incomplete

Oct 22, 2007

On URL: http://technet.microsoft.com/en-us/library/ms135931.aspx among other things there is an VB example for "Creating and Configuring Output Columns" of Custom Transformation Component with Asynchronous Outputs:

Public Overrides Sub OnInputPathAttached(ByVal inputID As Integer)


Dim input As IDTSInput90 = ComponentMetaData.InputCollection.GetObjectByID(inputID)
Dim output As IDTSOutput90 = ComponentMetaData.OutputCollection(0)

Dim vInput As IDTSVirtualInput90 = input.GetVirtualInput()


For Each vCol As IDTSVirtualInputColumn90 In vInput.VirtualInputColumnCollection


Dim outCol As IDTSOutputColumn90 = output.OutputColumnCollection.New()

outCol.Name = vCol.Name

outCol.SetDataTypeProperties(vCol.DataType, vCol.Length, vCol.Precision, vCol.Scale, vCol.CodePage)


Next
End Sub


When I copy-paste given code into ScriptMain of Ascynchronous Script Transformation Component I receive error message "sub 'OnInputPathAttached' cannot be declared 'Overrides' because it does not override a sub in a base class."

View 1 Replies View Related

Peculiar Behavior In Stored Procedure (outputs Are Returning Proper Vals For Uniqueidentifiers And Ints, Not Nvarchars)

Apr 27, 2005

Rather than the real code, here's a sample we came up with.
 
Here's the C# Code:
public class sptest : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
private DataSet dtsData;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
string strSP = "sp_testOutput";
SqlParameter[] Params = new SqlParameter[2];
Params[0] = new SqlParameter("@Input", "Pudding");
Params[1] = new SqlParameter("@Error_Text", "");
Params[1].Direction = ParameterDirection.Output;
try
{
this.dtsData = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings["SIM_DSN"], CommandType.StoredProcedure, strSP, Params);
Label1.Text = Params[0].Value.ToString() + "--Returned Val is" + Params[1].Value.ToString();
}
//catch (System.Data.SqlClient.SqlException ex)
catch (Exception ex)
{
Label1.Text = ex.ToString();

}
}
 
Here is the stored procedure:
 
CREATE PROCEDURE [user1122500].[sp_testOutput](@Input nvarchar(76),@Error_Text nvarchar(10) OUTPUT)AS
SET @Error_Text = 'Test'GO
When I run this, it prints up the input variable, but not the output variable.

View 2 Replies View Related

Reporting Services :: Adding All Columns To Table Without Adding One By One

Sep 3, 2015

Is there any way or option to get the all columns of dataset added to table when we add a table in data region. It will take lot of time to add one by one and also there are chances to add one column ore than once.

View 7 Replies View Related

Adding Column Where Adding Year To Date In Date Format

Aug 6, 2013

What is the syntax for adding a column where you are adding a year to a date in a date format? For example adding a column displaying a year after the participation date in date format?

View 1 Replies View Related

Retrieve AM Or PM

Aug 10, 2006

HI Chaps

very simple question this time

Is there any method availabe to retrieve AM or PM value from date, IN TSQL

hoping will get answer shortly

regards,

Anas

View 7 Replies View Related

RETRIEVE VALUE AFTER ADD FROM SQLDATASOURCE

Jun 29, 2007

I am using an SQLDataSource to add a product, this works fine, but I would like to know what syntax is used to retrieve the product ID in this case which is return by the SPROC
 
Thanks
 
Steve

View 1 Replies View Related

Retrieve Data

Jan 18, 2008

I need to retrieve points column from my database for the specific user that is signed on and sum all of them. How can I do it using the Gridview and also code in vb for a label? Thanks.  

View 4 Replies View Related

Retrieve Bit Type Value

May 7, 2004

I am trying to populate some controls on a web page with values retrieved from a sql server database recordset. The text type controls work fine. However I have a Check Box on my form. I get a runtime error when I try to write into it. So tried wrting the value into a text control and was suprised to see the value retrieved was "S00817". Heres the relevant line of code

Message.Innerhtml=MyDataset.tables(0).Rows(0)(12)

I would expect this to come up with a 1 or a 0. I get S00817 if the database record holds a 1 or a 0. So what is going on here?

View 2 Replies View Related

Retrieve A Particular Row From A Result Set

Aug 21, 2004

Hi all,

Is it possible to retrieve a particular row from a result set? For eg if my query returns 5 rows and i want to just retrieve the 3rd row from the result....is it possible? If yes...can someone tell me the syntax for it....would appreciate the gr8 help...

Thanks,
SQL Novice

View 1 Replies View Related

How Can I Retrieve Data?

Nov 19, 2005

Here is my sql procedure:
ALTER PROCEDURE dbo.SoftWareShow /* ( @parameter1 int = 5, @parameter2 datatype OUTPUT ) */ @SoftID uniqueidentifierAS SELECT [SoftID], [SoftName], [SoftJoinDate], [SoftSize], [SoftMode], [SoftRoof], [SoftHome], [SoftDemo], [SoftFirstClassID], [SoftSecondClassID], [SoftDesc], [SoftReadCount], [SoftDownCount],ltrim(rtrim([SoftUrlOne])) SoftUrlOne, ltrim(rtrim([SoftUrlTwo])) SoftUrlTwo, ltrim(rtrim([SoftUrlThree])) SoftUrlThree, ltrim(rtrim([SoftUrlFour])) SoftUrlFour FROM [SoftWare] WHERE ([SoftID] = @SoftID) RETURNwhere I retrieve data using sqldatasource, an error appear. how can do ?

View 1 Replies View Related

Best Way To Retrieve One Row For Use In Code

Mar 14, 2006

i have a SQL backend and some of the data in my tables is more or less configuration data and some times i only want to pull one row of data which i can do just fine with a SQL query but whats the best method to pull it. 
assume i have a query like this.
Select A, B, C from Table1 where ID=xyz
whats the easiest way to get A, B and C in to string variables?
I know i can use the sqldatasource control but i just feel there is too much overhead there.
whats your suggestions?
Thanks
Justin

View 1 Replies View Related

How To I Retrieve The First Value From A Table In T-SQL?

May 21, 2006

I want to do something similar to ExecuteScalar in ADO.net but instead in T-SQL.Basically I want to do a query that will return the first value in the table queried and put it into a variable.  How do I do this?Thanks in advance.

View 3 Replies View Related

How Can I Retrieve Nth Record Only?

Jul 6, 2001

Could you help me out?

I am interested in retrieving certain record among outputs.

For example, if I use the following sql,

select * from info order by name asc
====================================

then I can retrieve 25 rows from info table.

What I want to do is that I want to retrieve 15th record only among possible 25 records.

How can I solve this problem?

Thanks in advance.

View 2 Replies View Related

Retrieve Even If No Hits?

Apr 29, 2005

Hello!

is it possible to have the count(*) to display 0 when there is no matching hits for that n_id?

my query looks like this but only displays the n_id and it's respective count(*) when count(*) is more than 0...

select n_id, count(*) from tblTable
where nSomething > nSomethingElse AND nSomething IS NOT NULL
group by n_id

any idaes?

View 1 Replies View Related

Retrieve Second Max Value In A Sql Table

Feb 25, 2004

Hi all,
I want to retrieve the second maximum value of a column data present in SQL table.Please help....

A
----
10
25
23
15


here I want 23 as the result.

View 5 Replies View Related

Retrieve Insertiondate

Nov 23, 2004

Hi folks,

Does anyone know how to retrieve the date when data has been inserted

thnx in advance

View 4 Replies View Related

Retrieve Only 1 Row For Each ID (was Help On SQL! Urgent..)

Feb 3, 2005

i have a table called tblpictures which look something like this..

filename|ID
----------
1 |p1
2 |p1
3 |p2
4 |p2
5 |p3

is there a way to retrieve only 1 row for each ID? how will the select statement looks like?? please help me..

View 3 Replies View Related

Retrieve Using Bcp-urgent

Feb 25, 2005

hi gurus,
how to get " using bcp
e.g
select '"'+name+'"' from sysobjects
results
"name"
"name1"

I want to get the same using bcp ,so that i can populate into a file
something like

set @cmd='BCP "select '"' +name +'"' ,uid from sysobjects" QUERYOUT "' + 'vrs.txt' + '" -w -T -S -t , '
-- Executing the BCP Command
EXEC MASTER..XP_CMDSHELL @Cmd

View 3 Replies View Related

How To Retrieve One Record

May 23, 2006

I have a question, one user made mistake that she delete one record from a database. How can i retrieve this only one record. I just know how to restore the database.

Thanks.

View 3 Replies View Related







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