Skip to content

Tag: sql-server

Bulk insert csv file with semicolon as delimiter

I’m trying to import data from semicolon separated csv file into a SQL Server database. Here is the table structure The csv file is shown below: There are some columns that I don’t need, so I create a format file to import the data. The format file is shown as below Then I tried both bulk insert a…

How to get record by Date in my case using SQL Server?

I have 2 tables ProductLog and Product ProductLog Product The select statement RegNo value to be ProductLog.RegNo , which is Product.Date <= ProductLog.TransDate I want to get a result like below Expected Output I tried by ranking order Date by ASC, and where rank =1, it set all to lowest date value. (I un…

Is there an UPDATE equivalent command to SELECT json data

Is there a way to update the data retrieved from the below select (in this case, change “MS220” to something else)? It’s difficult enough to do select from JSON in some cases. I’m not sure how to update just a single element. Answer Try JSON_MODIFY() with the path ‘$[0].Name&#821…

While loop function union function end

I want to loop the code shown below. I would like to use the [getpublicholidays] function for a variable number of years and merge them (union). Unfortunately I don’t know how to use the function in a loop with union. Can someone help? Answer If you are looping for X years, each time you loop to a new y…

@@ROWCOUNT shows as 0 when deleting using dynamic query SQL

I am facing a trouble when using dynamic query and when trying to get the number of deleted records using @@ROWCOUNT Here is my QUery Here after the dyanimic delete query (inside my cursor) I am trying to store the number of deleted records into another table using @@ROWCOUNT. But it shows as 0. I didnt under…

SQL Server: show string majority

I am looking to make a query in SQL SERVER that will allow me to display in a grouping the string that appears in most cases. Not the amount, not the maximum, but the string that is displayed in most cases: colA colB colC A 10 ccc A 20 aaa A 35 bbb A 25 aaa A 10 aaa B