Transact SQL :: Find Last Transaction Of A Particular Type For Each Customer

Nov 12, 2015

I am working with SQL 2012 Express and I have a table with all transactions of invoices and payments for each customer. I am looking to find the last transaction detail of either two particular types of transactions (but not both) for each customer. So far I have tried various combinations around

SELECT        MAX([sbt::dte]) OVER (PARTITION BY [sbt::code]) AS LastPayment, [sbt::folio], [sbt::typ], [sbt::net] 
FROM dbo.tblSalbatTxn
WHERE      ([sbt::typ] = 13 OR [sbt::typ] = 17) 

Then there are some cases where customers have made more than the one of the same transaction type on that same last day which I would then like to sum the net value for that day of that transaction type.

I have also worked around this but it filtered the transaction type after it found the last transaction for each customer irrespective of it's transaction type.

SELECT        TOP (100) PERCENT a.[cl::code], a.[cl::alpha], b.[sbt::folio], b.[sbt::typ]
FROM            dbo.tblSalAccounts AS a INNER JOIN
                         dbo.tblSalbatTxn AS b ON a.[cl::code] = b.[sbt::code]
WHERE        (b.[sbt::dte] =
                             (SELECT        MAX([sbt::dte]) AS Expr1
                               FROM            dbo.tblSalbatTxn
                               WHERE        (b.[sbt::typ] = 11 OR
                                                         b.[sbt::typ] = 17) AND ([sbt::code] = b.[sbt::code]))) 

View 8 Replies


ADVERTISEMENT

Transact SQL :: How To Find Transaction In A Backup

Oct 22, 2015

I have heard about fn_dblog() function, Is it possible to find a transaction in a backup using fn_dblog() function?

View 3 Replies View Related

Transact SQL :: Sum Quantities For Given Transaction Type

Nov 4, 2015

My data is in 4 columns and multiple rows, like this

PartNo  Quantity TransactionType         TransactionDate
aaa       25         Incoming                    2015-03-01
aaa       25         Incoming                    2015-03-01
aaa       50         Transfer                     2015-03-02
bbb       30         Incoming                   2015-03-03
bbb       30         Transfer                     2015-03-03
ccc        50         Incoming                   2015-05-15
ccc        75         Incoming                   2015-05-20
ccc        50         Transfer                    2015-05-18
ccc        75         Transfer                    2015-05-21

What I need to achieve is sum the quantities for a given transaction type, group it by Part Number and add an additional column where the Transaction Date for Transfer Type rows would become the Transfer Date. Each part would have one row. The resulting data would look like this.

PartNo   Quantity   IncomingDate   TransferDate
aaa        50           2015-03-01      2015-03-02
bbb        30           2015-03-03      2015-03-03
ccc         125         2015-05-15      2015-05-21

How to achieve this goal.

View 5 Replies View Related

SQL Server 2008 :: Find Locations With MAX Sales Amount Per Customer

Feb 13, 2015

I have an invoice table with customer, date, sales location, and invoice total. I want to total the invoices by location by customer and see what location sells the most to each customer. My table looks like this.

CustDate LocAmt
A1/1/2014 1520
A1/1/2014 1560
A1/1/2014 2575
A1/1/2014 3580
B1/30/2014 15100
B1/30/2014 15200
B1/30/2014 2575
B1/30/2014 25150
B1/30/2014 35250

I want to get this, because for customer A, location 35 had the largest SUM of sales and for customer B, location 15 had the largest SUM.

CustLoc
A35
B15

If I have to use CTEs to get there, I can do that too. Just a little lost on how to get only the one location per customer.

View 2 Replies View Related

Transact SQL :: Multiple Occurrences Of Same Product And Same Customer

Nov 5, 2015

I am trying to build a query to identify customers that purchased the a specific product (e.g. db1.product_id = '123') on different dates.  All of the information needed is in the same db.  How do I do this?

Select db1.customer_id,
db1.product_id,
db1.purchase_date
From db1

View 20 Replies View Related

SQL Server 2012 :: Query Design - Find Most Recent Datetime Record Each Day For A Customer

Apr 2, 2015

So I have a query that need to find the most recent datetime record each day for a customer. So I have a query that looks like this:

SELECT
dhi.[GUID],
dhi.[timestamp],
la.[bundle_id],
dhi.[value]
FROM
[dbo].[DecisionHistoryItem] as dhi WITH(NOLOCK)

[Code] ....

View 4 Replies View Related

Transact SQL :: Merge Two Rows Into One Based On Same Customer Number

Oct 26, 2015

I have a table Customer with below column

CustomerNumber , FName,LName,DOB

I have either 2 or 1 row for each customer number  I want to write a SQL to pull data into 1 table based on same CustomerNumber, if only one row is present for the particular customer number it should pull null in FName2,LName2,DOB2 columns.

example:
CustNumber  Fanme   Lname   DOB
1  Sam tiller 08/26/1981
1  Joe   timy  01/02/1986
2  jack  niks   09/09/1990

Result I want:
CustNumber Fname1  Lname1 DOB1 Fname2 Lname2 DOB2
1  Sam  Tiller 08/26/1981 Joe  timy 01/02/1986
2  Jack  niks  09/09/1990 null null null

View 7 Replies View Related

Transact SQL :: Multiple Occurrences Of Same Product And Same Customer Filtered By Region

Nov 18, 2015

I successfully used the query below to identify customers that purchased the a specific product (e.g. db1.product_id = '123') on different dates.  Now I need to only pull the purchases from a particular region (client_cd = '593') that purchased a particular product on different dates.  How can I do this?

select distinct T.* from db1 T1
where exists (select 1 from db1 T2 where T2.CustomerId = T1.CustomerId and T2.ProductId = T1.ProductId and T2.PurchaseDate
<> T1.PurchaseDate) and T1.ProductId = '123'<o:p></o:p>

View 3 Replies View Related

Transact SQL :: Calculate Column Purchasing Rate Per Customer For Product And Region

Oct 22, 2015

I have a table Product2 as the attachment at the bottom. Now i want to create a Column "Purchasing rate" over Product and Region like this. I tried some Code but it gave me still Error.

createtableProduct2
(
[product] [varchar](255),
[Region] [varchar](15),
[Subregion] [varchar](25),

[Code] ....

View 5 Replies View Related

Analysis :: Find Amount Distribution Across Different Transaction Types Under Spend Transaction

Jul 27, 2015

I created a Calculated measure in cube something like this : ([TransType].[TransTypeHierarchy].[TransTypeCategoryParent].&[SPEND],[Measures].[Transaction Amount]). To get only spend transactions. Now, I want to slice this measure with same hierarchy to find the amount distribution across different transaction types under spend transaction. But this query behaving like the measure doesn't have relation with measure.

you can think this as below query:
WITH
MEMBER SPEND AS ([TransType].[TransTypeHierarchy].[TransTypeCategoryParent].&[SPEND],[Measures].[Transaction Amount])
SELECT NON EMPTY {SPEND} ON 0
,NON EMPTY ([TransType].[TransTypeHierarchy].[TransTypeCategoryParent]) ON 1
FROM [CUBE]

View 6 Replies View Related

CREATE TYPE Failed Because It Could Not Find Type

Jul 28, 2006

Hello --

I am having a UDT problem. When I run the Create Type command. I receive the "could not find type" error. I have seen other posts on here related to the default namespace in VB.NET. When I add the namespace I receive "Incorrect syntax near '.'." What is the format of the EXTERNAL NAME parameter. Thanks for any help. Code below...

Incorrect Syntax Error:

DROP ASSEMBLY CadSqlUdtsCREATE ASSEMBLY CadSqlUdtsAUTHORIZATION [dbo]FROM 'E:CAD.NETCADUDTsReleaseCadSqlUdts.dll'WITH PERMISSION_SET = SAFEGOCREATE TYPE dbo.ReportingAreaUDTEXTERNAL NAME CadSqlUdts.[CadSqlUdts.CadSqlUdts].ReportingAreaUDT;GO

Could Not Find Type Error:

DROP ASSEMBLY CadSqlUdtsCREATE ASSEMBLY CadSqlUdtsAUTHORIZATION [dbo]FROM 'E:CAD.NETCADUDTsReleaseCadSqlUdts.dll'WITH PERMISSION_SET = SAFEGOCREATE TYPE dbo.ReportingAreaUDTEXTERNAL NAME CadSqlUdts.ReportingAreaUDT;GO
What's up??

View 3 Replies View Related

Find Fileds Type

Jun 7, 2004

How Can I Find Fileds type (for example Bit or nvarchar or ntext ,...) in Sql Server;
with how sql parametr or query ?

View 2 Replies View Related

Help! I Need To Find Users W/ The Same &#39;Type&#39;

May 30, 2001

We are evaluating users. We need to isolate certain users and certain groups. I can not figure out how to use a stored procedure or a script to filter a list of ALL users with the same 'Type'. Does this make sense? Any advice would be appreciated. I am on a deadline here and i could use any input u might offer. I can always TYPE them in using the EM - Security - Login, but I thought that there might be an easier way to do it.
Thanks! Billy

View 4 Replies View Related

Query To Find The Top 3 In Each Type

Mar 7, 2006

Hi

I need help in finding the query which will provide the following resultset from the below table..

Table :
create table product_stocks(product_id int , product_type varchar(20) , no_of_units int)

Data:
insert into product_stocks values(1,'A',30)
insert into product_stocks values(2,'A',70)
insert into product_stocks values(3,'A',60)
insert into product_stocks values(4,'A',40)
insert into product_stocks values(1,'B',90)
insert into product_stocks values(2,'B',60)
insert into product_stocks values(3,'B',70)
insert into product_stocks values(4,'B',40)
insert into product_stocks values(1,'C',40)
insert into product_stocks values(2,'C',50)
insert into product_stocks values(3,'C',80)
insert into product_stocks values(4,'C',90)

Result Set:
product_type product_id no_of_units
--------------- ------------- --------------
A 2 70
A 3 60
A 4 40
B 1 90
B 3 70
B 2 60
C 4 90
C 3 80
C 2 50

i.e The result set gives the top 3 products in each product_type based on the no_of_units.

thanks

View 14 Replies View Related

Find Type Of A Column

Jan 30, 2007

hi

is it possible to find a column's type inside stored procedure?? I am going to get the name of the table and then work with the columns and I just need the type of the column if I have had the name of it

regards

View 1 Replies View Related

CLR Integration - Could Not Find Type '??' In Assembly '??'.

Jul 5, 2006

Hi,


I'm new to Integration services and .Net programming but am trying to
create a dll that I can access from Sql server 2005.


The dll read's an xml file and carries out some processing. I've run
the code as an console app and it works fine.


I have created the assembly in sqlserver thus:


create assembly PinCodeLoader from
'C:PinCodeLoaderPinCodeLoaderPinCodeLoaderinDebugPinCodeLoader.dll'
with permission_set = external_access


But when I try to reference the assembly from a stored proc


create procedure dbo.interface_processPinCodefile(@filename
nvarchar(1024))
as EXTERNAL name PinCodeLoader.PinCodeloader.Main


I get the following error:


Msg 6505, Level 16, State 1, Procedure interface_processPinCodefile,
Line 3
Could not find Type 'PinCodeloader' in assembly 'PinCodeLoader'.


I understand the context of the syntax should be
assembly_name.class_name.method_name. The first lines of the code in
the DLL are as follows


namespace PinCodeLoader
{
class PinCodeLoader
{
static void Main(string[] args)
{


Therefore assembly = PinCodeLoader, class_name = PinCodeLoader and
method_name = Main. Which should equal
EXTERNAL name PinCodeLoader.PinCodeloader.Main, I thought.


Has anybody come across this or can they offer any assistance?


Many thanks,


Paul

View 5 Replies View Related

How To Find Out To Which Type Of Sql Server I Connect To

May 21, 2008

Hi

I have an java program which can connect to sql 2000 or 2005.I am using jdbc 2005 and can connect to sql 2000 or 2005.My problem is that the server is given at runtime by the user and i have to find somehow out to what type of server i am connecting to(2000/2005).
Can anybody help?


thanks

View 3 Replies View Related

Help Troubleshoot Could Not Find Type In Assembly

Jan 3, 2006

I am attempting to create a CLR Procedure.  I was able to create the assembly, but I am unable to create a procedure on the assembly.  This is the error I receive:

Msg 6505, Level 16, State 1, Procedure DINEServiceProc, Line 2

Could not find Type 'DINEServiceProc' in assembly 'DINEService'

Here is the VB code to create the class:

<code>

Imports System

Imports System.Data

Imports System.Data.Sql

Imports System.Data.SqlClient

Imports System.Data.SqlTypes

Imports Microsoft.SqlServer.Server

Partial Public Class DINEServiceProc

<Microsoft.SqlServer.Server.SqlProcedure()> _

Public Shared Sub ServiceProc(ByVal iMsg As String, ByVal iMsgType As String)

Dim conn As SqlConnection

'Create an in-process connection to the instance of SQL Server

conn = New SqlConnection("Context Connection=True")

Dim DINEService As New DINEService

Try

conn.Open()

DINEService.ProcessStartRequest(iMsg, iMsgType)

Catch sqe As SqlException

'Console.WriteLine(sqe.Message)

Return

Finally

conn.Close()

End Try

End Sub

End Class

</code>

And here is the code to create the assembly and the procedure:

<code>

USE [ServiceBrokerTest]

GO

/****** Object: SqlAssembly [DINEService] Script Date: 01/03/2006 10:38:00 ******/

CREATE ASSEMBLY [DINEServiceProc]

AUTHORIZATION [dbo]

FROM 'D:EHITServiceBrokerDINEServiceDINEServiceinDebugDINEService.dll'

WITH PERMISSION_SET = SAFE

GO

CREATE PROCEDURE dbo.DINEServiceProc

(

@msg nvarchar(MAX),

@msgType nvarchar(MAX)

)

AS EXTERNAL NAME DINEServiceProc.DINEServiceProc.ServiceProc;

</code>

What am I doing wrong here?

View 11 Replies View Related

Find And Rollback An Open Transaction

Oct 15, 2007

We have a locked table and all I need is a way to show all open trans, so I can roll teh offender back

View 1 Replies View Related

Could Not Find Type 'StoredProcedures' In Assembly 'HelloWorld'

Aug 13, 2007

Why would you get this error?

CLR Class


Code Snippet
Partial Public Class StoredProcedures

_
Public Shared Sub HelloWorldStoredProcedure()

SqlContext.Pipe.Send("Hello World")
End Sub
End Class





SQL Code To Test



Code Snippet
USE CMM
GO
-- Drop Pervious Version
DROP ASSEMBLY HelloWorld
GO
--Add Assebly
CREATE ASSEMBLY HelloWorld
FROM 'C:My DevelopmentSQL2005 CLRHelloWorldHelloWorldobjDebugHelloWorld.dll'
WITH PERMISSION_SET = SAFE;
GO
--Check that Assembly worked
SELECT * from CMM.sys.assemblies
--Build Procedure
CREATE PROCEDURE HelloWorldSP
AS
EXTERNAL NAME HelloWorld.StoredProcedures.HelloWorld
GO
--Test
EXEC HelloWorldSP
GO






SQL Error




Code Snippet
Msg 6505, Level 16, State 1, Procedure HelloWorldSP, Line 2
Could not find Type 'StoredProcedures' in assembly 'HelloWorld'.


What have I done wrong?

View 18 Replies View Related

Find Transaction That Generated 4 Go In Journal File

Apr 28, 2004

We are using SQL Server with logshipping.

I noticed in the last two days the presence of 2 bigs journal files
(about 2Go each, transfered from primary to secondary ).

I want to know if there is a way to see what was the operation that lead to have this to big 2 log files
(sql statement or transaction... : with Oracle for instance, if we have chance, we can find this kind of info in
a dynamic views by the name of : v$sqlarea...)...

Thanks in advance

View 1 Replies View Related

Find Time Period For A Type Of Alarm With Overlaps

Apr 18, 2015

I have a dataset (DATA) like this-

Store Start End Type
XXXX 02-03-2015 10:04:00 02-03-2015 10:08:00 1
XXXX 02-03-2015 10:06:00 02-03-2015 10:10:00 2
XXXX 02-03-2015 10:09:30 02-03-2015 10:12:00 1
YYYY 03-03-2015 20:04:00 03-03-2015 20:12:00 1
YYYY 03-03-2015 20:06:00 03-03-2015 20:10:00 2
YYYY 03-03-2015 20:09:00 03-03-2015 20:16:00 1
YYYY 03-03-2015 20:15:00 03-03-2015 20:18:00 2
YYYY 03-03-2015 20:17:00 03-03-2015 20:22:00 2
YYYY 03-03-2015 20:21:00 03-03-2015 20:27:00 1

The output of this file (RESULT) is-

Store Start End Mins of Type 2 only
XXXX 02-03-2015 10:04:00 02-03-2015 10:12:00 00:01:30
YYYY 02-03-2015 20:04:00 02-03-2015 20:27:00 00:05:00

So for each Store (Store is unique in the table), I am rolling up the intervals with overlaps to create a single interval.

Now, for each store, I want to find the time period for purely type 2. So if there is an overlap, type 1 has the dominance. And I want the sum of time period of whatever is left for type 2.

I have written this code but not able to address the overlap issue:

alter table [DATA] add Outage float;
update [DATA]
set Outage = DATEDIFF(SECOND,[Start],[END])
alter table [RESULT] add [Outage_Type1 (%)] float,[Outage_Type2 (%)] float;

[Code] ....

View 11 Replies View Related

Transact SQL :: How To Find A Node

Nov 8, 2015

i have a table below like :
Id    ,    Request   

int     nvarchar(100)   
and in Request field i put below data :
1 <request><F3>353535</F3><F6></F6></request> 2 <request><F5>353535</F5><F6></F6></request>3 <request><F3>353535</F3><F6></F6></request>

now i need to a query that i can find records that exists <F3> and if exists , remove just the <F3> tag

 below like :
1 <request><F6></F6></request> 2 <request><F5>353535</F5><F6></F6></request>3 <request><F6></F6></request>

View 18 Replies View Related

Column, Parameter, Or Variable #1: Cannot Find Data Type SqlDatareader

Sep 28, 2006

Hello Everyone,A have a Managed Stored Procedure ([Microsoft.SqlServer.SqlProcedure]). In it I would like to call a UserDefinedFunction:public static SqlInt32 IsGetSqlInt32Null(SqlDataReader dr, Int32 index)   {    if(dr.GetSqlValue(index) == null)      return SqlInt32.Null;    else      return dr.GetSqlInt32(index)   }I than allways get the following ErrorMessage:Column, parameter, or variable #1: Cannot find data type SqlDatareader.Is it not possibel to pass the SqlDatareader to a SqlFunction, do the reading there and return the result.My original Problem is, that datareader.GetSqlInt32(3) throws an error in case there is Null in the DB. I thought SqlInt32 would allow Null.Would appreciate any kind of help! Thanks

View 1 Replies View Related

SQL Server 2008 :: Find Out Type Of Replication Pull Or Push

Apr 28, 2015

SELECT
P.Publication
,P.Publication_type
,S.Subscriber_ID
,S.Update_Mode
FROM MSPublications P
INNER JOIN MSSubscriptions S
ON P.Publication_ID = S.Publication_ID

give me publication_type=0. So it is transactional replication but how do we know that is pull or push?

View 2 Replies View Related

Reporting Services :: Find Items With Type Name Search Condition

May 17, 2012

The following 

SearchCondition[] sc = {new SearchCondition() {                                               
Name = "TypeName"
,Values = new string[] {"Report"}         
,Condition = ConditionEnum.Equals
,ConditionSpecified = true
}};
catalogItems = ReportService2010.FindItems("/"
,BooleanOperatorEnum.And
,new Property[] {new Property(){Name = "Recursive",Value="True"}}
,sc
);

Returns the following error

System.Web.Services.Protocols.SoapException: The TypeName field has a value that is not valid. ---> Microsoft.ReportingServices.Diagnostics.Utilities.InvalidElementException: The TypeName field has a value that is not valid.
at Microsoft.ReportingServices.WebServer.ReportingService2010Impl.FindItems(String Folder, BooleanOperatorEnum BooleanOperator, Property[] SearchOptions, SearchCondition[] SearchConditions, CatalogItem[]& Items)
   at Microsoft.ReportingServices.WebServer.ReportingService2010.FindItems(String Folder, BooleanOperatorEnum BooleanOperator, Property[] SearchOptions, SearchCondition[] SearchConditions, CatalogItem[]& Items)

The type appears to be correct. I've tried type of "Folder" and receive the same error.

View 5 Replies View Related

Cannot Find The Reporting Services Content Type In Share Point

Aug 16, 2007

Hi,

I installed the SharepointRS.msi add-in and configured the Reporting Services to the sharepoint integration mode. After the installation ,I am supposed to find a new section in the Application management of Central Administration Tool of sharepoint called Reporting services. But i am not able to find that.

View 1 Replies View Related

Cannot Find The Reporting Services Content Type In Share Point

Aug 16, 2007

View 1 Replies View Related

Select CASE - Add Up Amounts Based On Transaction Type

Dec 18, 2014

Getting Incorrect Syntax near the keyword 'and'

This table returns multiple records for an Invoice.

Based on the transactiontype_desc the Amount_Paid_DC is a different value. Trying to add up the amounts based on the transactiontype.

select DebtorNumber, InvoiceNumber, Sum(Amount_Invoiced_DC) AS InvAmt,
case transactiontype_desc when 'Sales Invoice' then sum(Amount_Paid_DC) else 0 end as AmtPaid,
case transactiontype_desc when 'Discount/Surcharge' and Amount_Paid_DC < 0 then sum(Amount_Paid_DC) else 0 end as DiscountAmt
FROM BI50_BankTransactions_AR_InvcDt_H
group by debtornumber, Invoicenumber

View 6 Replies View Related

Transact SQL :: How To Find Duplicates For Different Fields

Oct 27, 2015

I have a table that has Serial numbers and MSDSID numbers and many other fields in the table.

What I need to figure out is if the table contains a distinct Serial number with different MSDSIDs.

So If I have in the table

Serial          MSDSID          Date          Size...
001                 20            1/1/2015        5
002                 21            1/1/2015        3
001                 22            2/1/2015        1
003                 21            3/1/2015        1
004                 23            1/15/2015      5
003                 22            1/20/2015      6
004                 23            2/21/2015      5
002                 21            4/25/2015      4

I would like the results to show:

Serial            Count
001                  2           the count is 2 because Serial 001 has an MSDSID of 20 and 22
002                  1           the count is 1 because Serial 002 only has MSDSID 21
003                  2           the count is 2 because Serial 003 has an MSDSID of 21 and 22
004                  1           the count is 1 because Serial 002 only has MSDSID 23

It would be even better if the results just showed where the count is greater than 1.

View 5 Replies View Related

Transact SQL :: How To Find Mail Is Queued

Jul 19, 2015

I want to send an email twice a day, from database. So I have planned to make a storedproce which will be called by a job (which will select some record from one table and put it in other table based on a flag) but I want to run it in a transaction so that if email is send successfully then only it should commit else it should rollback.

How  can i find that "Mail queued" now i should commit.

View 4 Replies View Related

Transact SQL :: How To Find If A Column Is Used Anywhere In Database

Oct 20, 2015

I have looked around quite a bit, but mostly what I have found is looking to see if a table is used or if a column is in a stored procedure and honestly most of what I have seen does not work.

I want to reduce our nightly import by removing any columns that are not being used. We insert into our staging tables, Stage1 for example. And say Stage1 has column1 and column2. If those columns are not being used, then I want to remove them from Stage1. The only catch is that every Stage1 table has a v_Stage1. v_Stage1 should have all the columns from Stage1, but doesn't always. So I need to know what columns from Stage1 are used somewhere other than v_Stage1 and what columns from v_Stage1 are not used. 

View 14 Replies View Related

Transact SQL :: How To Find Alphanumeric Formats

Jun 12, 2015

create table example (f varchar(10))

insert into example values('fd')
insert into example values('fd')
insert into example values('fd1')
insert into example values('fd23')
insert into example values('fda23')
insert into example values('fd23g')

output:-

[A-Z][A-Z]
[A-Z][A-Z]
[A-Z][A-Z][0-9]
[A-Z][A-Z][0-9][0-9]
[A-Z][A-Z][A-Z][0-9][0-9]
[A-Z][A-Z][0-9][0-9][A-Z]

How to write SQl query to fetch this type of output.

View 6 Replies View Related







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