Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. briangriffin

    Function Returning Rowcounts

    I don't write a ton of functions, but this one has me stumped. -- ============================================= alter FUNCTION rptContractInvoiceLineTax ( @InvoiceLineAmount money, @TaxAreaID smallint, @TaxGroupID smallint ) RETURNS money AS BEGIN --set NOCOUNT off DECLARE...
  2. briangriffin

    Calculating differences every two rows

    If possible, I'd like to calculate the differences between every two rows (bold rows to be added): 9/2022 1000 9/2021 900 Variance 100 10/2022 1000 10/2021 1200 Variance (200) I'm guessing I would use lead/lag and some kind of loop, but if anyone has something...
  3. briangriffin

    Need to update with data from next record

    Dataset looks like this: Account OrderDate 100 5/1/2020 100 5/5/2020 100 6/1/2020 200 6/1/2020 200 6/2/2020 200 6/7/2020 I need the first order only, plus the order date of the next order, and discard the other records: Account...
  4. briangriffin

    Runaway Job

    I have a job scheduled via SQL Server Agent that has been running successfully every 15 minutes for many months. Today a user alerted me that the resulting data seemed stale, and when I looked in the job history the most recent instance was several hours ago. There was no stop date on the job...
  5. briangriffin

    Insert Filtered List

    I have data in columns such as this: Dept. Date Revenue 1000 2/1/2019 $1000 1000 2/2/2019 $2000 1000 2/3/2019 $3000 1001 2/1/2019 $4000 1001 2/2/2019 $5000 1001 2/3/2019 $6000 I need to be able to look up the department number and return all...
  6. briangriffin

    Greater Than/Less Than joins

    I have a table of surgical procedures: Account [tab] ProcedureCode 999 [tab][tab][tab]X1235 And a table used to cross reference procedures to billing codes: RangeStart [tab][tab][tab] RangeEnd X1234 [tab][tab][tab] [tab][tab][tab] X1345 X2345...
  7. briangriffin

    Calculate visits based on cutoff date

    I have a group of patients participating in a special program. I need to compute the number of hospital visits for each patient before and after they joined this program. Patient table looks like this: PatientID ActiveDate InactiveDate PreActiveVisits 111...
  8. briangriffin

    Looping Values Through a SP

    I have working code that splits values into a variable table: I need to take the first two values, determine if the StringValues match, and if so pass both strings from the Value field as input parameters to another SP. If the StringValues don't match then ignore. Then take values 2 and 3...
  9. briangriffin

    Need to delete pairs of records

    I have a recordset in a temp table that contains records like these (in addition to many other records that I want to keep): Account EffectiveDate SequenceID UndoneDateTime UndoneSequenceID 9999 1/1/2016 13:00 4 9999 1/1/2016 13:00 8...
  10. briangriffin

    Performance Issue When Filtering on Nulls

    I have a fairly simple query that runs in a few seconds - similar to this: select patient, room, max(intime) as InTime, OpDateTime from some tables group by patient, room, OpDateTime where OpDateTime is not null However, when changing to where OpDateTime is null then the query takes ten...
  11. briangriffin

    Calculate Price Based on Order Date

    Order history table looks like this: PurchaseOrderID LineID DateTime Price 24111 1 2014-12-22 23.89 24111 1 2014-12-23 19.17 24111 1 2015-04-21 25.42 This code: select tb1.PurchaseOrderID, tb1.LineID...
  12. briangriffin

    Identifying Changed Data

    I've started getting a flat file each day of all employees and the usual HR data - not a lot, about 700 employees and 20 fields. Every employee is in the file every day. Right now I'm working on the ETL piece to get it all into a table, and I think I'll store all the data each day for auditing...
  13. briangriffin

    Updating based on date range of another field

    These requirements always leave me grasping for the most efficient approach. I have a table of hospital admissions and readmissions, each record contains an patient number that is unique to the patient and consistent across all admissions. Some visits are flagged in the database as readmissions...
  14. briangriffin

    Error Converting to Numeric in Where Clause

    This query works fine: [code] select b.VisitID, cast(c.ResultRW as numeric(20,2)), isnumeric(c.ResultRW) from Livendb.dbo.LabRequisitions a inner join Livendb.dbo.LabSpecimens b on a.VisitID = b.VisitID and a.RequisitionID = b.RequisitionID and a.SourceID = b.SourceID inner join...
  15. briangriffin

    Flatten Rows Using FOR XML PATH

    Source data looks like this: PurchaseOrderNumber POLineNumber TextSequence TextLine 13472 1 1 This 13472 1 2 Is 13472 1 3 Text Found this code...
  16. briangriffin

    Need educating on log files

    Using SQL Server 2008 R2. I have a database that is used to store audit information. Recovery mode is simple, and if the entire db got wiped out we could recreate it easily. One of the tables grew very large - about 230 million records - and the db size is 159 gigs. The log file grew to over...
  17. briangriffin

    Excel 2007 If Then Formula Help

    A1: Y B1: 1 C1: ??? A2: Y A3: N Need formula in C1 to return 'Y' if: B1 = 1 AND A1 = 'Y' and A2 = 'Y' and A3 = 'Y' OR IF B1 = 2 and A1 = 'Y' and A2 = 'Y' Seems like I can get either the test for A cell values or the test for B1 value working, but not all in one formula...
  18. briangriffin

    Install Crystal on BOE 4 server

    I have a problem report that is getting the 'database configuration incomplete or incorrect' message when scheduling or viewing from BOE 4 server. I'd like to install Crystal on the server for troubleshooting purposes, but I recall that sometimes this creates problems if not done in a specific...
  19. briangriffin

    Referencing CTE Multiple Times for Updates

    I'm trying to update a summary table multiple times using a cte for the values - it works fine the first time, but then I get "Invalid object name cte_receipts" This works: with cte_receipts as (select BillingID, InsuranceID, count(BillingID) as ReceiptCount, sum(Amount) as ReceiptTotal...
  20. briangriffin

    Find Most Recent X Records per Customer

    New to MySQL - I could probably get this working in SQL Server, but I wouldn't be confident that the syntax would translate. Simple task: multiple records per customer: RecordID Customer 1 Joe 2 Joe 3 Joe 4 Joe 5 Sue 6 Sue 7...

Part and Inventory Search

Back
Top