Input: When Process ID = 610 ID Value 50 2 60 16 // 2 80 128 I have two separate queries that fetch two values from the same table so I am trying to merge them together instaed of calling the table twice. When this is run the where clause applies to [value1] and nothing is set for [value2] I
Tag: sql-server
SQL dynamic output tables
right now I have 2 tables. The first one has all the sales done by sales persons throughout each week, this table updates every week and only displays the sales of the current week (erases the data and starts over next week), the second table is a record of all sales done ever. SALES FOR THIS WEEK OCTOBER(9 TO 15)(updates
Condition Based Join in SQL Server
I have the following tables Invoice Organization Customer I’m trying to conditionally join these tables by the following condition: If PTypecd = ‘I’ then data come from the Customer table And if Ptypecd = ‘O’ then data come from the Organization table into the Invoice table. the query i tried so far: How does this condition be used in Join?
Field contains or is equal to another field
I am trying to write a query to return results where “Column B” is equal to or contains “Column A”. I need both, because some fields in Column B are an exact match for field in Column A, and sometimes the value in Column B is the value from Column A with additional characters added on the end. Example Column
Find sum of hours for each date worked
I have a table of timesheet entries set up like this: id job_id employee_id hours_worked date_worked 1 1 111 8 2022-10-01 2 1 222 8 2022-10-01 3 1 222 8 2022-10-02 4 2 222 8 2022-10-03 5 2 111 8 2022-10-04 6 2 222 5 2022-10-05 7 3 111 8 2022-10-04 8 4 333 8 2022-10-07 9 4 111 3
SQL Query to find top item of each group and display details from other tables
I am looking for a query to be able to identify the top-selling items (quantity) per location and to display details about that item and store. My tables are currently organized as such: Stores StoreID Location StoreName 1 San Diego Ralph’s 2 San Francisco Ralph’s 3 Sacramento Ralph’s Products ProductID Name Category 1 Milk Food 2 Eggs Food 3 Reese’s
How to assign integer values to based on id in SQL Server
I have a table like this: id value 15 a 15 b 18 c 19 d 20 e 20 f I want to create a select query with replaces the id value with integers starting from 1. id value 1 a 1 b 2 c 3 d 4 e 4 f This is my expectation. I am using SQL Server
What can I use instead of “Set Identity Insert On”?
I have stored procedure in SQL Server. In this procedure, I delete duplicate records and insert one unique records to table. When I insert new unique record I am using below script. Everthing is okey with this script but in the production SET IDENTITY_INSERT command needs to ALTER permission. Giving this permission should be dangerous so I can’t give this
Insert differences between 2 tables into 3rd table
I have total of 3 tables in my database. My Testing1 and Testing2 table have two exact columns (ItemID and ItemPath). My Testing3 have three columns (ItemID, ItemPath and Source). I’m trying to compare Testing1 with Testing2 and insert the difference to Testing3. I’m able get the the difference but I’m just wondering how can modify it to meet this
UNION Results from same SQL each with Different Parameter values
I have SQL that pulls data for a given timeframe. I want to run the SQL multiple times and merge/union the results together into one result set. Currently I copy the SQL and change the date ranges. As an example: Since I need to repeat this for multiple years, I would like to make the year a parameter and execute