How to zero out all negative numbers in a group-by T-SQL statement

Tags: , , ,


I have a T-SQL query where I want all negative quantities to be zeroed out. SELECT p.productnumber, v.[Description], SUM(i.Quantity) as quantity FROM ... LEFT JOIN ... LEFT JOIN ... LEFT JOIN ... ...

Tags: sql sql-server

Drop a temporary table if it exists

Tags: ,


I have two lines of code in SQL that create two tables on the fly, i need to do something like IF TABLE EXISTS DROP IT AND CREATE IT AGAIN ELSE CREATE IT my lines are the following ones ...

Best practices of structuring stored procedures

Tags: ,


As a developer mainly writing c# I have adopted some good practices when writing c# code. When I sometimes write stored procedures I have trouble applying those practices to the stored procedure code. ...

Tags: count mysql sql

SQL: How to get the count of each distinct value in a column?

Tags: , ,


I have a SQL table called "posts" that looks like this: id | category ----------------------- 1 | 3 2 | 1 3 | 4 4 | 2 5 | 1 6 | 1 7 | 2 Each category number corresponds to a category. How ...

Tags: sql

SQL query: make a report for all products

Tags:


I need help to build SQL query. I have 2 tables table PROJECT and PRODUCT, which has this fields: PROJECT: PROJECTCODE PROJECTNAME PRODUCT: ITEMCODE ITEMNAME PROJECTCODE REPLACEDBYCODE The ...

Solution for: Store update, insert, or delete statement affected an unexpected number of rows (0) [closed]

Tags: , , , ,


I found a solution for people who get an exception: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were ...

Tags: oracle sql substr

Query to get all those names of employees,who have ‘A’ as their middle character in their name

Tags: , ,


E.g:- BRAKE,CRANE etc. In my employees table , I have ENAME,ENO,JOB,SALARY. Here, I want to extract out those enames that have an 'A' as the center character in their name. If length of ename is ...

Tags: ms-access sql

SQL to Query text in access with an apostrophe in it

Tags: ,


Please help me with this because I cannot seem to get it right I am trying to query a name(Daniel O'Neal) in column names tblStudents in an access database however access reports a syntax error with ...

MySQL PRIMARY KEYs: UUID / GUID vs BIGINT (timestamp+random)

Tags: , , , ,


tl;dr: Is assigning rows IDs of {unixtimestamp}{randomdigits} (such as 1308022796123456) as a BIGINT a good idea if I don't want to deal with UUIDs? Just wondering if anyone has some insight into ...

Tags: join mysql sql

Count number of occurrences in SQL

Tags: , ,


I have a table with the following structure: (table_name, column_name) and for each row in this table I need to query the column_name in the table_name and do a COUNT(column_name) GROUP BY ...