Showing posts with the label tsql

[FIXED] Any way to edit data on MS-Access form using SQL View with two tables

Issue From what I've read it should be possible to edit data described by a view if the data be…

[FIXED] WHILE loop to get 2 blocks of XML

Issue With T-SQL (I cannot use C# or any other scripting language due to application limitations) I…

[FIXED] Script for TSQL

Issue Please help me write a Transact-SQL script. There is a table with conditional columns PK_ID …

[FIXED] Referring to a Column Alias in a WHERE Clause

Issue SELECT logcount, logUserID, maxlogtm , DATEDIFF(day, maxlogtm, GETDATE()) AS daysdiff FROM…

[FIXED] Table with identity field: Best SQL query to get Ids of deleted records?

Issue I have a table with an identity field. What the best SQL query to get the Ids of all the dele…

[FIXED] Calculate a Running Total in SQL Server

Issue Imagine the following table (called TestTable ): id somedate somevalue -- -------…

[FIXED] Group multiple rows into one base on the value of a column

Issue I want to group multiple rows into one based on the value of a column. Given this data: SEL…

[FIXED] How to convert an integer value to time (HH:MM:SS) in SQL Server?

Issue I have a set of integer value which can be either a single digit to 6 digit number. Now I wan…

[FIXED] What do more than 2 single quotes mean in SQL Server (T-SQL)?

Issue In this one stored procedure being called by an API to update a record, there's lots of i…

[FIXED] Command for adding a default constraint

Issue There appears to be at least two ways to add a default constraint using straight T-SQL. Am I …

[FIXED] How to find diff between two strings in SQL

Issue I have two strings, I want to get difference between contents of two strings in SQL ?? for …

[FIXED] generate fixed number of rows in a table

Issue Not able to word the question properly, so couldn't search what I want. All I need is a d…

[FIXED] When it's necessary to check @@trancount > 0 in try catch block?

Issue Sometimes I saw the following code snippet. When is the if @@trancount > 0 necessary with…

[FIXED] Get consecutive days with condition

Issue There is a table with three columns: CREATE TABLE #t1 ( Id INT ,VisitDate…

[FIXED] Remove the time part in Datediff

Issue This is my query: SELECT DISTINCT 'wk ' + TRIM(CONVERT(varchar(max), DATEADD(Wee…

[FIXED] SQL query to retrieve column name among 3 columns in table whose values are mutually excluse ie.one among them will be 'Y' whose col name to be found

Issue I have a query in which multiple joins and select from various tables are used. One table str…

[FIXED] How to query all system under SystemTypes in SQL database in a json format

Issue I have a SQL table like below class="s-table"> GroupID CountryName CityNam…

[FIXED] DateTime2 vs DateTime in SQL Server

Issue Which one: datetime href="https://msdn.microsoft.com/en-us/library/bb677335.aspx&quo…

[FIXED] How should I pass a table name into a stored proc?

Issue I just ran into a strange thing...there is some code on our site that is taking a giant SQL s…

[FIXED] How to remove outliers in SQL using Standard Deviation?

Issue I currently have a dataset that contains transactional information, including dates, an amoun…