My goal is getting list of SQL server databases which files have been deleted. In other words. I attach a db from mount, then close the mount so actually I have the attached db without files. At …
Tag: tsql
Return first order by each month
I am trying to modify my current query to return the first order for each month in each year. Here is my full table and my current query. select orderdate, sum(UnitPrice*Qty) AS …
SQL Server: Update table based on JSON
I am trying to update rows in table based on JSON I have. JSON has the following structure: Table dbo.sensors has same structure + few more columns. To insert such JSON object, not array, into table, I would do it this way: So I have 2 questions: how to iterate over each element in JSON array and update each row
Extract string between double quotes in SQL
I have a string and I need to return the characters between the double quotes ‘((“Name 1” and “Name 2”) or “Name 3”) I need to return I have used the function below to split the string but I am getting the (( and the Or and AND etc .. which I don’t want and unfortunately I can’t be certain
Issue converting JSON string into decimal
This question may answer on many threads but I am unable to find answer specific to my problem. Q: I am getting data from API (in json format) where all columns are coming as string and inserting …
insert xml data to table stored procedure sql server
I have xml in following format I want to insert them in table so the table should have 4 records in the example. columns are name and alias. How can I achive this using cursor or something else? What i have tried. In cursor for entity i try insert alias value,but only first alias is taken. Answer
Adding a new column with data
Below is my table: Now I want to add a new column called ‘Gender’ with values M,M,M,F in 4 rows respectively. I first added a new column using: Now I understand I can add data one by one by using: But how do I add all 4 data at once? Answer You don’t, unless there is some other piece of
Passing in parameter to where clause using IS NULL or Coalesce
I would like to pass in a parameter @CompanyID into a where clause to filter results. But sometimes this value may be null so I want all records to be returned. I have found two ways of doing this, but am not sure which one is the safest. Version 1 Version 2 I have found that the first version is
LEFT JOIN: The multi-part identifier “_” could not be bound
For the below query I am getting following error: Earlier these were implicit joins but trying to resolve i changed them to explicit inner joins but still I am getting this error. What can I try next? Answer Never use commas in the FROM clause. Always use proper, explicit JOIN syntax. So, write the FROM clause as: You no longer
How to have a NULL instead of No Value from a query
I had a query like: Then I tried But when it doesn’t find the named table returns not output, Value or Null value or anything I can work on. This is going to be used as a crosscheck. Does anybody have any idea? Answer Thanks for those who payed attention to what I exactly asked and for their responses. Here