sql-server

I can't insert NULL values into datetime2 fields in SQL Server

Hi! I'm using CakePHP. When trying to insert a null value into a field it turns into 1900-01-01 00:00:00. Here's a sample of my code: $this->save(array( 'date_signed' => null )); What seems to be the error and how do I fix it? Thanks in advance! ...

MS SQL Specific Tables Hanging at Queries

I have SQL Server 2008. I run a query in a table on a database. The weirdest thing keeps happening. I run a simple select statement on the table. I know there are 62 rows in the table but it gets stuck at row 48 and goes on "querying...". Waited already for hours and it didn't move on from there. I only know of two programs, and on...

MySql TABLE data type

MS SQL Server has a TABLE data type which can be used in stored procedures, Does anybody know if MySQL has an equivalent data type? I've had a look over the docs but can't seem to find anything, so I presume it doesn't exist, but perhaps somebody has created a workaround ...

Is it worth the trouble to avoid using the SqlParameterCollection.AddWithValue method?

Several articles tells you that you should avoid using AddWithValue method because it can lead to poor execution plans and performance. Should I go through my DAL and change all parameters to specify the SqlDbType? Is it worth the loss in maintainability? (If I change a column-type from varchar(50) to varchar(100) I would need to change ...

SQL Service Broker Peek on queue

Hi, I'm writing a C# application that uses SSB queues to communicate with other systems. When receiving a message from a SSB queue, I am not always sure I am able to handle it. Therefore I would like to peek at the queue (or maybe just being notified that there is a message, not neccessarily it's content), but at the same time using the ...

T-Sql Multiple Criteria On Where Clause

Scenario I'm using SQL Server 2005 I have a T-Sql query that has multiple criteria to search on the WHERE clause. I'm certain that I'm doing this in a very inefficient and long way round. How can I ensure that I don't have to manually type out all the criteria? Instead I want to pass in the criteria via a SELECT * clause. Current Query...

Return dataset in dataflow

Hi All, Could I get ideas on retrieving the dataset using lookup method. Basically, my scenario as I have source data needs to lookup for other source table and on matching column from source I need to get all the records from other source data. its a one to many relations. I tried Lookup but gives only one record on matching condition...

What is the Varchar(Max) equivalent for DB2?

In DB2, is there a datatype that allows the string to grow and shrink dynamically like Varchar(Max) in SQL Server? ...

Getting dates based on week number

Hello. I have some rows in my database that contains some dates. I need to select all dates based on a weeknumber, how is this possible? ...

General SQL Server query performance

Hey guys, This might be stupid, but databases are not my thing :) Imagine the following scenario. A user can create a post and other users can reply to his post, thus forming a thread. Everything goes in a single table called Posts. All the posts that form a thread are connected with each other through a generated key called ThreadID. T...

updating only date part from datetime in sql server 2000

hi Experts, I have data in the table like the following. col1 col2 col3 -------------------------------------------------------- 6/5/2010 18:05:00 6/2/2010 10:05:00 Null 6/8/2010 15:05:00 6/3/2010 10:45:00 6/5/2010 11:05:00 6/3/2010 15:05:00 Null 6/7/2010 12:0...

HowTo: Update DB row with save for prior to change state

Hi, i have a table with order details. User is able to modify these details after he adds them for first time. My question is what is more right way to save prior to update changes. By that i mean not just subjective way of thinking but drawbacks in each way i list or maybe your suggestion... I thought of creating Orders history table w...

Database Schema Versioning Strategies

I work on a project that uses a reasonably large database, the live version weighing in at somewhere around 60-80GB. The live database is the only real definitive source of our schema, and because of its size duplicating this database is too slow to be done often. This means we have ended up developing our database schema in a pretty ad ...

Can I Rollback a restore ? SQL Server

Hi, Is there anyway to rollback a restore which performed by mistake? (using a different databases' backup file) SQL Server Thanks... ...

How do I create a Pivot query for this simple case?

I have a very simple query that I need pivoted, but I haven't got a clue how to turn it into a pivot table from what I've read in the literature. Everything I've read involves hard-coded columns or is too complex. It has to be simpler, or I just can't grasp CTE's. The query is a list of user names and clients they have access to. So I...

how to determine date when service pack was applied to SQL Server instance?

For an instance of SQL Server 2005/2008, how can one determine the date and time when a service pack was applied to the instance? Is there a system table or view that stores that information? ...

What does "foo" mean in this SQL Server Query ?

for eg... SELECT * FROM ( SELECT RANK() OVER (ORDER BY stud_mark DESC) AS ranking, stud_id, stud_name, stud_mark FROM tbl_student ) AS foo WHERE ranking = 10 Here foo is present...actually what it does ?.. ...

Interesting LinqToSql behaviour

We have a database table that stores the location of some wave files plus related meta data. There is a foreign key (employeeid) on the table that links to an employee table. However not all wav files relate to an employee, for these records employeeid is null. We are using LinqToSQl to access the database, the query to pull out all no...

How can I create a locationID type of column to denote what server created a row in SQL Server Merge Replication?

I want to setup merge replication between two SQL Server 2008 Servers. For the Primary Key’s, I’d like to use a composite key: an identity column plus a column that will denote which server the row was created on (locationID column). Any ideas on how to do this? I’m not sure if you could use a trigger or a function to insert a defau...

Single SQL Server Result Set from Query

Hi Please advise on how to merge two results in to one using SQL Server 2005. I have the situation where an Account can have up to two Settlement Instructions and this has been modeled like so: The slim-ed down schema: Account --------------------- Id AccountName PrimarySettlementId (nullable) AlternateSettlementId (nullable) Settl...