I want to create several stored procedures (or user-defined functions) within a transaction. CREATE PROCEDURE statement must be the only statement in the batch, so I have to use following template: …
Tag: sql-server-2012
How to Create SELECT for Total sales for each region
I want to write a query to get Total sales for every region, but i cant figure the way to do it. I have these tables: Region(RegionID, Name) Client(ClientID, Name, City, Country, Email, RegionID) …
Count alpha characters in string field in SQL Server
I am using SQL Server Management Studio v17.9.1. I have column in a database table that contains alphanumeric strings. I need to count the letters in the string and produce a table of the aggregate …
How to account for double entries in a card swipe table?
How do I account for accidental swipes in a card swipe table? I tried selecting the max(time_cst) by grouping them on entry. It did not solve the problem. http://www.sqlfiddle.com/#!18/06cc8/2 EmpID …
Error Handling for numbers of delimiters when extracting substrings
Situation: I have a column where each cell can have up to 5 delimiters. However, it’s possible that there are none. Objective: How do i handle errors such as : Invalid length parameter passed to …
Multiple CTE where clauses referece CTW column
For example WITH UserDetail (UserId, UserName) AS ( SELECT TOP(10) U.UserId,U.UserName FROM UserTable U ), UserAction (ActionName,ActionType) AS ( SELECT TOP(10) A.ActionName,A….
Select rows until running sum reaches specific value
I have the following data: DECLARE @t TABLE (usr VARCHAR(100), dt DATE, amount INT); INSERT INTO @t VALUES (‘a’, ‘2018-01-01’, 100), — 100 (‘a’, ‘2018-02-01’, 100), — 200 (‘a’, ‘2018-03-01’, 100), -…
Select data from date range between two dates and times
I have pretty much the exact same question as logged here Select data from date range between two dates But when I used the solution given it does not work for me. Only difference is that my table has date and time in the one column. So I want to be able to return all values that fall within the
CONVERT issue in sqlserver with Msg 529 error
This statement is giving me a error VALUE column Datatype is TEXT in the RESULTS table. How can i overcome the above problem. please help ! Answer You can’t convert from text to datetime You must apply two convert operations. The first: From text to varchar The second: From varchar to datetime So your query will become: Plus: text datatype
SQL Server 2012 takes long time on simple alter to add NULL columns
I have a problem to alter table in SQL Server 2012, it takes a long time to add 04 columns being allowed NULL to large table with 340 columns and approximately 166M rows and 01 non-clustered index This problem happens only specific table after restoring. I’m waiting the execution for 10 hours but it’s not finished so I must cancel