I have a column in a table with words separated by comma. I need to count each occurence of each word My column looks like : (‘a, b, c’), (‘a, b, d’), (‘b, c, d’), (‘a’), (‘a, c’); (fiddle at the bottom) Here is what I get : But here is what I expect Here is what I’ve done so
Tag: tsql
SQL Get count of each item within a SQL query
I have this table ID PhoneID PhoneName Active Status 1 1 a 1 1 2 1 b 0 2 3 2 c 1 1 4 2 d 1 1 5 2 e 0 3 6 3 f 1 1 7 3 g 1 1 8 3 h 1 1 9 4 i 0 4 10 4 j 1 1 And
Retrieve the last valid value from a previous date
I have the following table “Rates”: aDate realRate isBusinessDay 01-04-22 1.10 1 02-04-22 1.20 1 03-04-22 1.30 1 04-04-22 1.40 0 05-04-22 1.50 0 06-04-22 1.60 1 07-04-22 1.70 1 08-04-22 1.80 1 09-04-22 1.90 1 10-04-22 2.00 0 11-04-22 2.10 0 12-04-22 2.20 0 13-04-22 2.30 0 14-04-22 2.40 1 15-04-22 2.50 1 16-04-22 2.60 1 17-04-22 2.70 1
how to get data grouped by ids
I have grouped data in a temporary table according to id_card. There are multiple activities for each card. I want to send 1 email for all activities happened on that particular card. But, I don’t know how to get data according to ids. should i use cursor for fetching the ids ? Example in the table, want 2 rows for
Calculate years based on months in SQL Server
I want to write a function that takes the number of months as a parameter and does the following: I can hardcode all of this using case statements but I wanted to know if there is a dynamic way of doing it. Thanks! Answer Try this:
Cursor is storing values in a variable but not updating in another table Sql Server
I have write a cursor in which i am getting values from a table using cursor and updating these values in another table . While testing i have analysed that values are storing in table and update is also working because sql server message shows that 1 row has been update but the values from cursor are not being update
How can I include strings which contain special characters in my WHERE clause?
I am using SQL Server 2014 and I am faced with the following problem in the WHERE clause of my T-SQL query. My WHERE clause will list the names of towns. However some of the names contain characters like an apostrophe in them. Example: ST JULIEN D’HOTMAN My T-SQL looks as follows: The above does not work because one or
Need to get the value from a column whose column name is based on a value in another table
Table A has columns ID, COL1, COL2, COL3. Table B has columns AID, ColumnName. I need to get the [ColumnName] value in Table A based on the value of [ColumnName] in Table B. In the example below: For ID 1, I need to get the value of column COL1 (This is the value of [ColumnName] for AID 1 in Table
How can I avoid “stringly typed” code in T-SQL?
Consider some code like I believe that the technical term for such poor code is “stringly typed”. The key issue in the above code is that decisions are being made based on a string output that the developer needs to type and consistently get correct. If anything goes wrong, the language will be incapable of throwing errors. In a traditional
mssql execution order guarantee when conversion in where clause
I have following scalar function Problem with that is, that o.aValue could not only have numeric values, so that the convertion can fail, if it is executet on other rows of idmv_value_basic, where attrName is not ‘OM’. For some unknown reason this morning, our MSSQL-Server changed the execution order of the where conditions and the convertion failed. How could I