Skip to content
Advertisement

Tag: sql-server

Bind where clause to a column

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

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

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

Advertisement