sql-server

SQL Server CASE WHEN without using CASE WHEN

Is there a way to rewrite a Transact SQL statement that uses a CASE WHEN structure to do the same without using the CASE WHEN? I'm using a product that has a built-in query designer and its own pseudo-SQL. It has limitations on what I can use with SQL Server and Oracle. So I have this column that, when the underlying database is Oracle,...

SQL Server 2005 - Passing 2-Dimensional Array to Stored Procedure

Hi, I am working on SQL Server 2005. Here I need to pass an array (2 dimensional, E.g: Emp No, Emp Name ) having multiple records from my ASP.NET application to a Stored Procedure. Would you please let me know if there is a way to do it? Many Thanks, Regards. Anusha. ...

Accessing output parameters before processing result set in SQL Server via jdbc

I am calling an 2005 MS SQL Server stored procedure using the MS JDBC Driver and want to access the output parameters before processing the result set as follows: proc = "{call mySproc(?,?,?)}"; conn = ds.getConnection(); callableStmt = conn.prepareCall(proc); callableStmt.setString(1,inputParam); ...

SQL Server: how do I find which column/row gave me an error?

Does anyone have any hints on the best way to find the source of an conversion or truncation error such as: Error converting data type varchar to numeric. String or binary data would be truncated. The statement has been terminated. When I'm inserting batches of data, I'll get these type of errors, and it then becomes a educated guess...

TSQL CTE and a Graph of Sorts

With a table of the following structure and sample data: TableActivity ------------- Type VARCHAR(8) Activity VARCHAR(8) RelatedActivity VARCHAR(8) Type Activity RelatedActivity ------------------------------------------ Start a - Transfer a b Start b ...

Is it possible to tell what query a given SQL Server process is running?

Our application has started having problems with SQL Server 2005 queries getting blocked. Is is possible to tell what query the blocking process is running? If it is possible how is it done? ...

Sql Server 2008 Reporting Services email on the fly solution

To all, I have noticed that other reporting tools allow you the option, at the time of running a report from the web interface, to either have it rendered to the browser or allow you to enter an email address have have the report sent to that address. This would be helpful for long running reports or reports that are fairly large. My ...

SQL Server Race Condition Question

(Note: this is for MS SQL Server) Say you have a table ABC with a primary key identity column, and a CODE column. We want every row in here to have a unique, sequentially-generated code (based on some typical check-digit formula). Say you have another table DEF with only one row, which stores the next available CODE (imagine a simple ...

Consume a WCF service from a console app as part of a SQL job?

I'm working with one WCF service which will be consuming records I queue up for it with another. Service A will package up an object containing a series of records (I guess an XML document, haven't nailed down the format yet) queried from a database, and submit it to Service B for processing. Service B is on a separate department's sys...

Getting at string data in SQL

I have a row entry with the following format: Site=[number];this=that;foo=bar; [number] above can be from 1...infinity. So I need to split out the [number] to use in another select statements where clause. Site=[number] is always at the beginning in the string and the data is always separated by a semi-colon. ...

Select statement performance

I'm having a performance issue with a select statement I'm executing. Here it is: SELECT Material.* FROM Material INNER JOIN LineInfo ON Material.LineInfoCtr = LineInfo.ctr INNER JOIN Order_Header ON LineInfo.Order_HeaderCtr = Order_Header.ctr WHERE (Order_Header.jobNum = 'ttest') AND (Order_Header.revision_number = ...

Invalid Object Name: Beginner using the AdventureWords db from a class

I'm trying to learn some C#.net. I'm just trying to expose the AdventureWorks database included in my C# class via a web interface. Here's the setup: I've got a DropDownList in on my ASPX page with an id of tableNameDropDown. It gets populated on Page_Load like this: protected void Page_Load(object sender, EventArgs e) { ...

Does SQL Azure support the FILESTREAM datatype

I am looking at using SQL Azure and wondering if it supports the FILESTREAM data type introduced int SQL Server 2008 or should I look at another solution. ...

reparenting hierarchyid values

If I have the following rows set up in a SQL Server 2008 table: Row Hierarchy 1 1/ 2 2/ 3 1/1 4 1/2 5 2/1 6 2/2 7 2/1/1 Currently row 5 is parented to row 2. I want to reparent row 5 to row 1, so it would now become 1/3 instead of 2/1. That much I have working so ...

SQL Server full log issue -- how to update the database?

I am working with SQL Server 2000, and trying to change the data type of a field from varchar to nvarchar, so that it can handle international characters. However, there is already a lot of data in that table, and when I try to save the change, I get the following error: Unable to modify table. ODBC error: [Microsoft][ODBC SQL Server ...

Insert rows in table if not found in another table

I have a table: Employee (employeeID) EmployeeRank (rankID, employeeID) Now I have another table that has all the employee's that are going to get a raise. DueForRaise (rankID, employeeID) I have to insert all the employees that are in DUeForRaise into the EmployeeRank table ONLY if they are not already there with the same rank. I...

Query to obtain average each 30 seconds

How can i calculate average of each 30 second? The following is the table structure Price TTime every minute 5-60 records inserted. The time is inserted by getDate(). I have to calculate average of every 30 seconds. ...

SQL Server 2005 Security

Here is the scenario. I have a SQL Server 2005 production database/server. It currently has developers and supporters who can connect to it. I need to create a security module that gives developers read-only access to all areas of the database. This means that a developer should be able to view all objects as well as scheduled activities...

Tool for comparison of SQL Server query plans?

Does anyone know of a tool that can be used to compare (relatively complex) query plans? I'm not looking for a guide to query plans, but just a tool that enables me to quickly see e.g. the different index use. EDIT: just to make it clear, I'm not looking for information about the plan, but a tool that can quickly point out the differenc...

SSIS Loop a list of connection strings in a master package, executing two other packages for each connection string

I am trying to figure out how to loop a list of connection strings in an SSIS package. MSDN suggests I can have an Execute SQL task generate a result set into a variable and use a For Each task to loop the results, but it's none too clear to me exactly how to create this. So I have a table with a single nvarchar column with a list of Sq...