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…
SQL best practice/performance when inserting into a table. To use a temp table or not
I have a select query that’s come about from me trying to remove while loops from an existing query that was far too slow. As it stands I first select into a temp table. Then from that temp table I insert into the final table using the values from the temp table. Below is a simplified example of the flo…
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.
How to get Total Overdraft amounts from a particular Date in SQL
I’m trying to get the total amount of overdraft accounts from an old Date, the goal is to get the total amount it was on the 31st of January. I have the following tables Users and Transactions. USERS (…
Retrieve values from the last object in a JSON object in Postgres
I have a Postgres table that has a field, KPI, containing a JSON object. It contains data for every week of the year. I want to return the values contained for the current week, in this case w5 which …
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. …
How can I get a count of how many times a distinct value appears in a column?
How can I find out how many times each distinct value appears in a column? NOTE: This is not a case of “how do I find distinct values in a column?” For example, this column contains five …