Dynamic pivot with Max(Date) from pivot

I want to keep this general so if it’s ok, I’d prefer to not use my specific data set. My general example: I have a table of customers who have many orders. I want a pivot table that shows how many orders each customer has had in each month (or general time frame). Suppose I […]

SQL Service Broker example not working

I have two databases on the same instance. One called ICMS, one called CarePay_DEV1 When a change happens in ICMS (Source), it needs to send a message to CarePay_Dev1 (Destination). I am new to Broker Services, and am trying to make a message go to the queue. Once that works, I will hopefully get the […]

Dynamic SQL Exception Handling in SQL Server

I’m executing the following Dynamic SQL on SQL Server 2008 via Java: BEGIN TRY BEGIN TRAN T1; DELETE FROM [MyDatabase].[dbo].[MyTable]; DECLARE @bulk_cmd nvarchar(max); SET @bulk_cmd = ‘BULK INSERT … ‘; EXEC (@bulk_cmd); COMMIT TRAN T1; END TRY BEGIN CATCH ROLLBACK TRAN T1; DECLARE @ErrorMessage NVARCHAR(4000), @ErrorSeverity INT, @ErrorState INT; SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = […]

How can I search for a sequence of bytes in SQL Server varbinary(max) field?

I am trying to write a query on SQL Server 2012 that will return varbinary(max) columns that contain a specified byte sequence. I am able to do that with a query that converts the varbinary field to varchar and uses LIKE: SELECT * FROM foo WHERE CONVERT(varchar(max), myvarbincolumn) LIKE ‘%’ + CONVERT(varchar(max), 0x626C6168) + ‘%’ […]

there is a process running select statement on tempdb database?

In the Activity Monitor, There is a process(belongs to a single PC) running select statement on tempdb database,it is always running. and i am unable to kill it. What should i do?

Handling Dates from Oracle to SQL Server 2005 using OPENQUERY

I have linked SQL Server 2005 to an Oracle Server, and am using OpenQuery() to pass data from Oracle to SQL Server. So, for instance, the following query works fine: SELECT * FROM OPENQUERY(ORACLE_LINK, ‘SELECT FIELD1 FROM ORACLE.TABLE1’); Everything works, unless I ask for a field which is a date/time in the Oracle database. For […]

condition in the stored procedure for the search of date is not functioning

I created a stored procedure which filters the records of license application by status, ship name and expiry date. The code had run for the filtering of the status and ship name except for the EXPIRY DATE. The function should filter the expiry date based on the input on the textbox using ajax calendar. I […]

SQL Server Management Studio: prompt for user input

Is it possible in SQL Server Management Studio to ask the user for input and based on that input proceed? I have a stored procedure which inserts some data into tables. When ever a user executes the stored procedure, I want a message to come up asking if he is sure he wants the stored […]

force number of rows to return in date range from SQL query

I’m running a query on our SQL (2012) database which returns a count of records in a given date range, grouped by the date. For example: Date Count 12/08 12 14/08 19 19/08 11 I need to fill in the blanks as the charts I plot get screwed up because there are missing values. Is […]

String or binary data would be truncated on cmd.ExecuteNonQuery()

I have an error while executing my project. I have two commands in this button. Can someone help me with this? I can’t detect the problem. It is working fine before but now it occurred a problem. I’m developing an library system SqlCommand cmd = con.CreateCommand(); cmd.CommandText = “INSERT INTO Borrowbook ([Student ID], ISBN, Title, […]

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