Skip to content
Advertisement

Tag: sql-server

Combine data with same ID

I have an assignment where I need to use aggregate functions in the queries. I keep running into a problem where there are multiply entries for the same ID, and I would rather them be combined into one run (added together for the same ID). Output below (IDs to be combined in column 3, “intTeamandClubID”): I want the “intTeamandClubID” to

Truncate table Dataverse

I am trying to truncate a table in Dataverse, so I have installed SQL Server Management studio, selected my database, and ran the query TRUNCATE TABLE tablename However, I get the error: Is there something that I am missing? Answer The SQL Connection to Dataverse is read-only The SQL connection provides read-only access to the table data of the target

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

Take oldest record in a set of rows

So, I have this problem, I have this set of records in a table TemperatureID CastingID TemperatureDateTime TemperatureValue 1421294 1073513 2021-01-07 11:53:00.000 1648 1421295 1073513 2021-01-07 11:54:00.000 1698 1421326 1073514 2021-01-07 22:00:00.000 1594 1421327 1073514 2021-01-07 22:11:00.000 1609 and this repeated many times. My problem is that I have to take only the oldest record for each set of CastingID

Extract the record for last hour for specific date

I am trying to extract the last hour (TKT_DT) record for number of tickets (TKT_DN) from sales table (PS_TKT_HIST) for specific date (BUS_DAT). I have the following code but it extracts the number of tickets (TKT_NO) for each hour. I want to filter the last hour only. Here is the code I used: I get the flowing results I want

How to select the best item in each group?

I have table reports: In human language: there are reports for each month. Each report could be in XML or CSV format. There could be 1-2 reports for each month in unique format. I want to select the reports for all months, picking only 1 file for each month. The XML format is more preferable. So, expected output is: Explanation:

Advertisement