Tag: sql-server-2012

SQL Server concurrent 5 timestamps in a columns

I would like to get an SQL Query that would help me to fetch the times in a row whichever lies with in 5 minutes and the count of times noticed should greater than or equal to 5? For Example: Column A 17:22:23 17:44:31 17:25:36 17:24:11 17:47:39 17:26:22 17:22:44 My results should fetch the below […]

MSSQL: Get Subtotal of a total

How can I write a query to get the subtotal of a total? Example is below. select task_id, client_id, SUM(value1 + value2) AS ‘Total 1’, SUM(value3 + value4) AS ‘Total 2’, –pseudocode SUM(Total 1 + Total 2) AS ‘Total 1 + Total 2’ from table1 GROUP BY task_id,client_id Expected Results: task_id | client_id | Total […]

INSERT INTO EXCEPT using only 2 identify columns

hopefully this is an easy one for you folk smarter than me. I am trying to perform an insert into a table from another matching table, but I only want to insert if the row doesn’t already exist. Some of these values in the row if it exists may be changed. Which is okay. I’m […]

Searching a string in stored procedure definitions fails when the definition is too long

I run this query to find references to MyTable in the stored procedures in my data base: SELECT ROUTINE_NAME, ROUTINE_DEFINITION, ROUTINE_TYPE FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_DEFINITION LIKE ‘%MyTable%’ However, I did not find anything, the problem is that ROUTINE_DEFINITION is limited to 4000 characters and the SP that operated on MyTable was longer. Using View Dependencies […]

No process is on the other end of the pipe (SQL Server 2012)

I’ve got this error: A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 – No process is on the other end of the pipe.) (Microsoft SQL Server, Error: 233) I know, there are similar questions on this site, and the answer […]

Copying user roles and permission from one database to another

I’m having the issue with the user permission in my new database. I copied this new database from different sever, that old server database has some users,granted permission to execute some procedures. after i backed up and restored in to new server all permissions were gone. I run sp_helprotect to find out the users and […]

SQL Stairstep Query Help Needed

I need some help producing a MS SQL 2012 query that will match the desired stair-step output. The rows summarize data by one date range (account submission date month), and the columns summarize it by another date range (payment date month) Table 1: Accounts tracks accounts placed for collections. CREATE TABLE [dbo].[Accounts]( [AccountID] [nchar](10) NOT […]

TSQL Execute result different in PHP and SSManagement Studio

I’m querying a MSSQL Procedure from PHP and SSManagement Studio and the result is different?? This query is getting the fields starting by tKey from the table. Two columns tKey1 and tKey2 exists Procedure sp_myProc DECLARE @tKeys VARCHAR(100); SELECT @tKeys = ISNULL(@tKeys + ‘,’, ”) + column_name FROM testweberp.INFORMATION_SCHEMA.columns WHERE table_name = myTable AND LEFT(column_name, […]

SQL inner join two tables from separate databases and update one of them

I have the following SQL query: UPDATE db1.dbo.oitems SET f2 = oo.f2, f3 = oo.f3, f4 = oo.f4 FROM db1.dbo.oitems o INNER JOIN db2.dbo.oitems oo ON o.orderid = oo.orderid Each table is in a different database and they have identical columns but different data with some matches in id but not in data. I simply […]

IS NULL versus <> 1 SQL bit

I have a bit column on a table in a SQL Server 2012 database. I am trying to retrieve all the rows where this bit column is either NULL or NOT TRUE. This query does not bring back what it should: (returns 0 rows) Select * from table where bit_column_value <> 1 This query brings […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.