Skip to content

SQL Server – grab part of string after a value sequence

I have a table called Note with a column named Notes. It has font info in the beginning which I don’t need. I’ve created a new column name final_notes and would like to grab everything after the “fs” plus two characters. The final result would be Answer We use PATINDEX to find the firs…

How to fix SELECT statement to return duplicates

Currently I am trying to return a three table join to find duplicate track titles that are in my a “track” table, and also return the track number | cd title from the other joined tables. My select statement is currently returning all the information from the joined tables but its not showing only…

Problem in SQL query #1066 – Not unique table/alias

I have a problem with this query: I get this error: 1066 – Not unique table/alias: ‘code’ Answer The error seems pretty clear. You have mentioned code three times in the from clause. What does code refer to? In your case, I think the solution is to remove all the references. The first should…

How to skip NULL (or 0) when using Row_Number?

I need to return the sequential number of a row based on values in ColValue. I need to do it until NULL occurs in a row, then start to count from the beginning. My original table is in the left picture, what I need is on the right (column RowNr): [ I tried various combinations of ROW_NUMBER but in vain.

Incorrect syntax near ‘)’ SQL SERVER

I am trying to find data of One Table where Weeks column is greater than result of Subquery.But somehow that is not running due to Incorrect syntax SELECT * FROM Table1 a WHERE CONVERT(DATE,SUBSTRING(…

Optimize SQL with multiple BETWEENs in WHERE

I have a query like this: SELECT […] FROM […] WHERE FirstInt BETWEEN 100 AND 200 AND SecondInt BETWEEN 100 AND 200 Those variables have to be in the same range. Is there any way to write sth. …