I’m afraid the answer to this is “NO, you can’t”, but since I can’t find this explained anywhere I’m gonna ask anyway. Given a user defined table type: And a function that returns that type: And another function that accepts that type: Since the return value of fnFind fits …
Tag: sql-server
Update the ColumnNo field to display the same number when the AppID and FootNote are the same
I am trying to update the ColumnNo field to display the same number when the AppID and FootNote are the same. I need it to display like the first image below. I have tried Which works in reverse. And some other functions to no avail. How can I flip this? Answer Use dense_rank():
Create a table on the SQL server with the data from an SQL query?
Is it possible to create a table on the SQL Server with the data from an SQL query? I am trying to make a data filter screen in an SQL database and I want to try to filter a result that has already been filtered before If you help me with an example I appreciate. Answer In SQL Server you
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…
Is there a way to achieve below using pivot or something else in T-SQL?
I’m trying to achieve below using pivot in T-SQL: brand a revenue brand b revenue` brand c revenue branch 1 20,000 branch 6 9000 branch 9 11000 branch 3 15000 branch 5 2000 branch 6 8000 branch 9 10000 branch 10 1500 branch 4 5000 However I’m getting this result: brand a brand b brand c branch 200…
How to use ‘Count’, based on a particular column in SQL
I have a query and which give the count greater than 1, but what I expect is I need the result to be based on particular column(Rollno.) How to achieve it. Table Studies The below query gives me Count but not as expected The query gave me the below result But the expected result is As you can see the
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
How do I make an incremental ranking per query system on SQL Server 2019?
Currently on SQL Server 2019, I have the following code: SELECT dbo.GroundTruth.QueryId, dbo.GroundTruth.Q0, dbo.GroundTruth.Id, RANK() OVER(ORDER BY dbo.GroundTruth.Similarity DESC) …