sql-server

Why isn't "String or Binary data would be truncated" a more descriptive error?

To start: I understand what this error means - I'm not attempting to resolve an instance of it. This error is notoriously difficult to troubleshoot, because if you get it inserting a million rows into a table 100 columns wide, there's virtually no way to determine what column of what row is causing the error - you have to modify your pr...

SQLServer Binary Data with ActiveRecord and JDBC

I'm using the activerecord-jdbc-adapter with ActiveRecord to be able to access a SQLServer database for Rails Application running under jRuby and am having trouble inserting binary data. The Exception I am getting is below. Note I just have a blurb for the binary data from the fixtures that was working fine for MySQL. ActiveRecord::Stat...

DBCC SHRINKFILE 1 sproc for multiple databases

I have a need to execute DBCC SHRINKFILE for multiple db's within the same sproc. I could create multiple sprocs so it runs within the given context, but I was curious if there were alternatives? ...

Images from SQL Server JPG/PNG Image Column not being Type Converted to Bitmap in HttpHandlers (consumed by Silverlight Client)

Our Silverlight 3.0 Client consumes Images stored/retrieved on the File System thorough ASP.NET HttpHandlers successfully. We are trying to store and read back Images using a SQL Server 2008 Database. Please find the stripped down code pasted below with the Exception. "Bitmap is not Valid" //Store document to the database private...

How to put foreign key constraints on a computed fields in sql server?

Table A has a computed field called Computed1. It's persisted and not null. Also, it always computes to an expression which is char(50). It's also unique and has a unique key constraint on it. Table B has a field RefersToComputed1, which should refer to a valid Computed1 value. Trying to create a foreign key constraint on B's RefersT...

Impact of ordering of correlated subqueries within a projection

I'm noticing something a bit unexpected with how SQL Server (SQL Server 2008 in this case) treats correlated subqueries within a select statement. My assumption was that a query plan should not be affected by the mere order in which subqueries (or columns, for that matter) are written within the projection clause of the select statement...

SQL IN Statement using like syntax?

I would like to do something like this i.e., use wild card characters in the in clause: SELECT * FROM mytable WHERE keywords IN ('%test%', '%testing%') This is not supported in SQL Server.... Is there some other way to achieve it... Looking for something other than: SELECT * FROM mytable WHERE keywords like '%test%' or keywords like...

How to reference a sql server with a backslash (\) in its name?

Givens: One SQL Server is named: DevServerA Another is named: DevServerB\2K5 Problem: From DevServerA, how can I write a query that references DevServerB\2K5? I tried a sample, dummy query (running it from DevServerA): SELECT TOP 1 * FROM DevServerB\2K5.master.sys.tables And I get the error: Msg 102, Level 15, State 1, Line...

SQL Server Upgrade 'Developer > Enterprise'

Hey guys, My company purchased Visual Studio Pro 2008 last year, which had a 'free' copy of SQL Server Developer, which I have been using for development. We are wanting to upgrade the copy of developer edition to enterprise (As we now want to use the server as a production server), and have purchased the licenses for this. Now... Mor...

Aggregate SQL column values by time period

I have some numerical data that comes in every 5 minutes (i.e. 288 values per day, and quite a few days worth of data). I need to write a query that can return the sums of all values for each day. So currently the table looks like this: 03/30/2010 00:01:00 -- 553 03/30/2010 00:06:00 -- 558 03/30/2010 00:11:00 -- 565 ...

SQL query optimization

I have a problem with my SQL query that take time to get all records from database. Any body help me. Below is a sample of database: order(order_id, order_nm) customer(customer_id, customer_nm) orderDetail(orderDetail_id, order_id, orderDate, customer_id, Comment) I want to get latest customer and order detail information. Here is m...

dbo in SqlServer

I'm converting database from Teradata to SqlServer. I've noticed all tables and procedures are named by the prefix "dbo." (e.g. "dbo.Table1"). I would like to know if and how I can get rid of "dbo" because it would make the conversion task a lot more easier. ...

PHP SQL Server Connection

I am using SQL Server as my backend for program.when i am try to connect with database which not shows any type of errors,but it is not working.Which is not getting connection. My code is like mssql_connect('servername', 'db_user', 'db_password') or die('Error'); The funny thing is which is not connecting and also which is not show m...

Is it possible to use SQL XML to insert, and get output from each record?

I would like to perform a SQL XML insert (on MSSQL), and in this case I need to insert a list of files into the DB (this is simple enough). However, there's an auto generated PK column (ID), and I need the ID for each newly created filename without performing a 2nd query. Is this possible? I guess it doesn't matter if the result is/isn't...

SQL Server Query Editors - any that warn of number of rows to be changed?

We're using SQL Server 2000 Query Analyser, and one issue we have is that very occasionally, when a user is updating our live database, they insert the incorrect/no(!) where clause. I know, not good, but it happens. Are there any editors that will warn of the number of rows that might be changed (if that is even possible) or even a way...

how to pass argument in sql query

how to pass argument in sql query ExecuteQuery("Delete from emp where empno = auguement); ...

order by for specfic column

I want to make order by ASC For specific column from more columns ...

SQL Server: How to trim all columns in a table

I have over 30 columns in my table (sql server 2008). Columns type are varchar(x). I know that in every column there is two extra spaces at the end of column value. How to use rtrim function for all columns and save this modification into this existing table? Edit: is there a way to do it using stored procedure or cursor where I don't h...

Inserting an attribute in all nodes of a xml using xml.modify

I need to read the whole xml one by one and then add attribute in every node of xml. Any idea how can I do this. I dont want to change the actuall xml. Just for the run time. ...

How do I automatically validate stored procedures against the database schema

A few years ago I came across a T-SQL technique to validate a stored procedure in SQL Server, but I cannot find it again ...