sql-server

Limiting rowcount of SELECT statements, with linked servers

I have these linked servers, A and B. Server A is running SQL Server 2008, and B is running SQL Server 2000. I have written a script to migrate data from a bunch of tables from B to A. The data is quite sensitive so I'm afraid I can't tell you anymore about that. I can, however, tell you that we are talking about a lot of data, worst ca...

Using uniqueidentifier SQL column type with Entity framework

For my primary key and identity in our Clients table I use uniqueidentifier column with a default value set to newsequentialid(). Inserting new rows through the management tool creates the values for the ID fine. Inserting from .NET 4 code via EF results into zero GUIDs (00000-0000....) being inserted. I create the entity with new, set...

datetime issue with 01/01/1900

i have a datetime column in sql server and its optional field and if the user decided not to enter then i want to insert the value as NULL in the table and i define something like this: @deadlineDate datetime = null when i am inserting into sql server i have this code in asp.net private DateTime? GetDeadlineDate() { DateTime? get...

Want to use Excel2010 cell column as driver for SQL Server 2008 query

Tough to believe I'm the only one but..I want to use the Connection functionality in Excel to connect to a SQL Server database and populate column X based upon using a value in Excel column A as the primary key, but unable to find out how. I have tried (typing in the command text window) select name from pbaTable where pbaid = (and ...

What is the Oracle equivalent of SQL Server's IsNull() function?

In SQL Server we can type IsNull() to determine if a field is null. Is there an equivalent function in PL/SQL? ...

Insert Null value in ADO Recordset

Is it possible to insert a null value into a field using the AddNew method of an ADO Recordset in VB6? In a typcial INSERT query, you would simply use NULL; however, I've discovered that this doesn't work through ADO; it inserts "NULL" instead. Is there another way to insert a null value when adding a new record? ...

Execute SQL Server scripts

How can I automate process of running all SQL scripts from given folder ? ...

Sql server stroed proc with computed values

I have to write a query with lot of computations. Is it a good idea to create indexed view with this computed columns instead of writing a stored proc? Thanks!! ...

SQL conditionally return history.

I have a table that has notes in it. It has a bunch of notes that automatically do different thing according to what someone does in the system. When an order is assined it makes a note that says "Order was assigned to 'name'" When an order is re-assigned it makes a note that says "Order was re-assigned to 'name'" When an order is ass...

New table not showing up in publication's article list in SQL Server 2008

I'm very new to SQL Server. I just had someone transfer my entire database from Access to SQL Server and I'm trying to get up to speed. This is a merge replicated database. I added a new table "EmailList" to the database "CRM", then went to the "CRM" Publisher properties in SMSS and noticed that when I expand the article list, my new ...

Update statement running for too long or not

I'm new to working with this much data (20 million rows) and I don't know what I should expect as far as query duration: update table set field = '1234' No index on field. This statement took 25 minutes. The database is set to Simple Recovery. Does 25 minutes seem too long? Table has 9 columns with small data types <50 varchar. ...

How to set up a development environment for SQL Server stored procedures?

Hi, I have recently started working on a legacy application that has most of its business logic in stored procedures spread over two or three SQL Server databases. Currently all code is also edited in the live environment. As I am new to the codebase, I don't really want to make any changes in the live environment and therefore I'm try...

How to use SqlCommand to CREATE DATABASE with parameterized db name?

To put it short. I've got two simple helpers: private SqlCommand CreateCommand(string text) { SqlCommand cmd = new SqlCommand(); cmd.Connection = connection; cmd.CommandType = CommandType.Text; cmd.CommandText = text; return cmd; } void SetParameter(SqlCommand cmd, string p, strin...

How to handle a nullable foreign key field in Entity Framework?

I have a table with a nullable integer field that is a foreign key. When I try to set the entity model's Nullable property to True I get an error that states that fields of type Int32 can not be null. So if Entity Framework doesn't support nullable integers, how can I insert rows into the table with a null value? If no value is specified...

Between Date Literals

How do I make this work in SQL Server (2005)? The error message is 'Invalid column name' on the literals. SELECT tstamp, GVEA_Load_Net_MWH FROM DA.dbo.Oplog WHERE CAST(LEFT(tstamp,18) AS datetime) BETWEEN "01/01/2009 00:00:00" AND "01/01/2010 00:00:00" ...

Bulk Import into SQL server Table

Can you please help me with the syntax to bulk import this data: startIpNum,endIpNum,country,region,city,postalCode,latitude,longitude,dmaCode,areaCode 1.0.0.0,1.7.255.255,"AU","","","",-27.0000,133.0000,, 1.9.0.0,1.9.255.255,"MY","","","",2.5000,112.5000,, 1.10.10.0,1.10.10.255,"AU","","","",-27.0000,133.0000,, 1.11.0.0,1.11.255.255,"K...

sql server stored procedure cursor name conflict

I have a situation where one sql server stored procedure is calling another one and both happen to use cursors that have the same name. This is causing a conflict as apparently the cursors don't have visibility restricted to the stored procedure where they are declared. Is there any way to make the cursors private to the procedure th...

sql server 2008: setting up a username properly in order to connect from VBA

i set up a login (reviewer) under security for SQL SERVER and under the specific database i set up a User (qcvalues_reviewer) that references this login i have tried all these different ways to login into the database from vba: 'cn.Open "Provider=SQLOLEDB;Data Source=hermes;Initial Catalog=test;User ID=qcvalues_reviewer; Password=921...

SQL Server Update Query does not use Index

I have a update query that runs slow (see first query below). I have an index created on the table PhoneStatus and column PhoneID that is named IX_PhoneStatus_PhoneID. The Table PhoneStatus contains 20 million records. When I run the following query, the index is not used and a Clustered Index Scan is used and in-turn the update runs ...

Is MS Access a Relational Database?

The database which follows 12Rules of codd is a perfect relational database, I have read some where that No Database is Pure RDBMS... SQL Server is RDBMS.. however MS Access is not RDBMS, I am confused.. why so as we can created relations. links. in Access as well.. then what are the main criteria that defined a Database DBMS or RDBMS ?...