Skip to content

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 T…

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 …

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 …

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