I need to find customers that have a sum of credit transactions greater than or equal to a threshold amount and a sum of debit transactions less than or equal to the inverse of that same threshold amount. I also want to return the transactions whose aggregate transaction amount satisfies the credit and debit thresholds. I have come up with
Tag: sql-server-2016
SQL agent job creation error: Job ‘XXX’ is already targeted at server ‘YYY’
I am trying to create and SQL agent job on SQL Server 2016. Here is the use of sp_add_job. EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N’TEST_RUN_A_JOB_STEP’, @enabled=1, @…
TSQL PIVOT/UNPIVOT Multiple Summarized Columns
Seems this is a popular topic but I can’t seem to replicate other answers. I have data that is already summarized by month/year for multiple categories. What I’m trying to get is this Here’s the query to provide the data I’ve used PIVOT a bunch of times, but with a single “category” of data. I can’t seem to get anything
Write a SQL query to calculate the balance in a card [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 1 year ago. Improve this question Can you please help me how to calculate the balance for each quarter The data table Script to create the table: Create Table CardTransactions (
SQL Server: Drop all Not Null constraints in all DB tables
How do I drop all Not Null Constraints in All Columns in every table using SQL Server ? Would like to loop run this query in all tables and columns, How to remove not null constraint in sql server using query Note: requirement is for all non-primary key columns. Similar Question: How to drop all Foreign Key constraints in all
SQL – Compare 2 tables and show non existent data
Ok, I have 2 tables that I need to do a comparison to. The idea is to show anyone in the database who has not purchased a specific product. Table 1 UserID Customer ProductsSold 1 John Cookies 2 …
how to add select statement in IN clause in pivot
iam using pivot table in SQL query.. i need to make some columns as rowss, but i need to use select statement in IN clause where we givt option like this normally we give option like but with select statement its giving me error?? what can be done. Answer use this i got answer from some of google posts
How do you get the size of the gap from LEAD or LAG?
In my table, I have messages grouped by threads. Using LEAD, I can get the next message within a thread… [ThreadNextMessageId] = LEAD(gm.GroupMessageId, 1) OVER(PARTITION BY gm.ThreadId ORDER BY gm….
Sql Grouping insight Xml
I need to get different row data to 1 row based with id and need to group by its status. I tried in several ways and finally found a solution using xml, but when I use xml I don’t get the output I want. This is a sample code I used to try the logic. returned output: expected output: Answer
How do I get this JSON output?
I need to create the following JSON from SQL server 2016. { “recipientList”: [ { “name”: “1”, “recipientType”: “User” }, { “name”: “2”, …