Skip to content

Tag: sql-server

SQL Server update column using previous value

I’m trying to formulate a filter in a table column. Table A has 3 columns spare_qty (plays the role of ID), alt (altitude, the Value to be filterd), Alt_derivative (the required Filtered_Value). The table contains about a million lines. My purpose is to populate column Alt_derivative at line X by the fo…

SQL : query for multiple conditions with multiple columns

How to query multiple conditions with multiple columns, like AND clause in AND clause. Example data The result that I need is without.. Country = Japan and ZipCode = 1010 Country = Canada and ZipCode = 3030 I try to write SQL like : but it’s not correct. Any help please ? Answer Just use not: You can ex…

How to copy column from one table into another table in SQL Server

I want to copy column state_name from table state into table district. here is my query. This code is working on mysql but not in SQL Server This is the state table This is the district table Answer In SQL Server, the corresponding syntax might be: This is more commonly written using an explicit JOIN: However…

How to get top selling items a year ago

I want to get the top selling product of the month last year. Example today’s month is May 2021, so I want to get the top selling products of May 2020, if the month changes to June, it automatically changes the @Date1 to June 1 and @Date2 to June 30. Here is my query for getting the top selling using