Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 6 m…
Tag: sql-server
SQL – Select with group by, Get data from the register with the max(date)
I have two tables in the database: Product and ProductVersion , each product can have n ProductVersions. ProductVersion has this fields ( Id, name, origin, date, provider ) I want a query where I get …
SQL SUM values in declared column into total and group by id
Hello people of the internet. Once again I seek your advice. I have multiple meter readers collecting power consumption every 5 minutes and storing to MS SQL Database. I execute SQL query to get a days worth of data from all meter readers and check how much power it has used every five minutes and returning a…
How to calculate Sum and Subtraction from two different table
I have two table “tbl_In_Details” and “tbl_Out_Details” Sample data for tbl_In_Details Now i want to calculate current stock i.e. (incoming – Outgoing) as Current_Stock i tried in such a way but not getting proper record please guide me where i need to modify my query: My output …
How to insert JSON file data to SQL Server table using sql command
I am not so familiar with SQL. I have a table in my SQL Server database called Product CREATE TABLE [dbo].[Product] ( [Age] INT NULL, [Name] NVARCHAR (50) NULL, [Id] …
Sql View with WHERE clause runs slower than a raw query
This runs in a constant time: However, this one takes about 7 seconds: Component is a SQL view which consists of the first longer query without WHERE clause. Why this happens? Does the view retrieve all records and then apply Where clause? Is there a way to speed up the second query? (without applying indexes…
Use empty table in SQL query
I have created a new SQL table of two column [Lot_no, Comment] which is empty. I have another table of two column [Lot_no, Product_Code] which has values. Problem: I want to create a SQL query where I retrieve [Lot_No|Product_Code|Comment] for some [Lot_No] but since no data is available for comment in first …
Finding cumulative sum using SQL Server with ORDER BY
Trying to calculate a cumulative sum up to a given number. Need to order by 2 columns : Delivery, Date. Query: Results: Expected results: Version: Microsoft SQL Server 2017 Answer You need a third column in the ORDER BY clause to break the ties on Contract_Date and Delivery. It is not obvious which one you wo…
Should I create a Joint table or add foreign key
I’m busy designing a database for my app, I made the relationship between tables… and after, I realized that instead of using foreign key and place it in another table I can only use a new joint table that will contain primary key for each table. Not sure if any one used to achieve it? Also Micros…
Operand data type varchar is invalid for avg operator
I keep getting the above error message “Operand data type varchar is invalid for avg operator” Can anyone fix it for me? PLEASE Thanks in Advance Answer Actually, the problem is that the implementation is incorrect. You don’t want to average timestamps (5h:3m:20s), but durations. Hence, you …