I need to create a INSERT script in order to insert in another database the same data. If in SQL Server I select “Script table as > INSERT To” I can easily recreate the skeleton for the INSERT …
What are the pros and cons of performing calculations in sql vs. in your application
shopkeeper table has following fields: Let’s say, I have the above table. I want to get the records for yesterday and generate a report by having the amount printed to cents. One way of doing is to perform calculations in my java application and execute a simple query and then loop through the records and convert amount to cents in
Cannot insert the value NULL into column
I’m having some problems. I am trying to get a table to update, however it is not updating because one of the fields contains rows with a NULL value. Heres the original query which gives no error: Now, the nextUpdate column might be NULL, so I am trying to accommodate for that with this query: You can see I’ve added
How to get the employees with their managers
This is what I want the output to look like: Employee Emp# Manager Mgr# BLAKE 7698 KING 7839 CLARK 7782 KING 7839 JONES 7566 KING 7839 MARTIN 7654 BLAKE 7698 …
How to get second-highest salary employees in a table
It’s a question I got this afternoon: There a table contains ID, Name, and Salary of Employees, get names of the second-highest salary employees, in SQL Server Here’s my answer, I just wrote it in …
What does SQL clause “GROUP BY 1” mean?
Someone sent me a SQL query where the GROUP BY clause consisted of the statement: GROUP BY 1. This must be a typo right? No column is given the alias 1. What could this mean? Am I right to assume …
Convert SQL Server DateTime object to BIGINT (.Net ticks)
I need to convert a DateTime type value to BIGINT type in .Net ticks format (number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001). The conversion should be perform in Sql server 2008 using T-SQL query For example: will convert to: Answer I have found a CodeProject article that may assist: Convert DateTime To .NET Ticks
Average of multiple columns
I have a table called Request and the data looks like: Req_ID R1 R2 R3 R4 R5 R12673 2 5 3 7 10 R34721 3 5 2 1 8 R27835 1 3 8 5 6 Now I want …
Creating a view for summary
I have a table of questions. The questions can be high priority, low priority, open/answered. What is the best way to create a summary. Should I use a view or several stored procedures? Table …
How to zero out all negative numbers in a group-by T-SQL statement
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 … …