sql-server

How to Query A DataGridView Using Linq

I have a DataGridView that I want to query using Linq (C# WinForm). I want to "count" rows where a certain criteria is met. For example, variable1 = "count rows where ColumnBoxAge > 3 || < 5" label1.Text = variable1 How to do this in C# WinForm using Linq? ...

Upgrading SQL 2000 32-bit to SQL 2008 64-bit

Hi, I have a number of databases on a Windows 2000 Server running the 32 bit version of SQL Server 2000. I need to transfer all the data and settings to a new server running the 64 bit version of SQL 2008 on Windows 2003 64 bit. Is this as simple as backing up the databases and restoring to the new server. Will this work with the system...

SQL grouping

I have a table with the following columns: A B C --------- 1 10 X 1 11 X 2 15 X 3 20 Y 4 15 Y 4 20 Y I want to group the data based on the B and C columns and count the distinct values of the A column. But if there are two ore more rows where the value on the A column is the same I want to get the maximum valu...

Select X Most Recent Non-Consecutive Days Worth of Data

Anyone got any insight as to select x number of non-consecutive days worth of data? Dates are standard sql datetime. So for example I'd like to select 5 most recent days worth of data, but there could be many days gap between records, so just selecting records from 5 days ago and more recent will not do. ...

Should there be a Transaction for Read Queries?

I've been reading that some devs/dbas recommend using transactions in all database calls, even read-only calls. While I understand inserting/updating within a transaction what is the benefit of reading within a transaction? ...

How can I use an SQL Pivot for this?

I have a data set that is organized in the following manner: Timestamp|A0001|A0002|A0003|A0004|B0001|B0002|B0003|B0004 ... ---------+-----+-----+-----+-----+-----+-----+-----+----- 2008-1-1 | 1 | 2 | 10 | 6 | 20 | 35 | 300 | 8 2008-1-2 | 5 | 2 | 9 | 3 | 50 | 38 | 290 | 2 2008-1-4 | 7 | 7 | 11 | 0 | 30 | ...

sqlnclir.rll being loaded and unloaded continuously

I'm working with SQL Native Client 9 in a C++ application that communicates with SQL Server 2000. I'm working on debugging things right now but something I've noticed that bothers me (mostly because it's creating significant clutter) is that sqlnclir.rll is being loaded and unloaded continuously and the following lines are being spammed...

MS SQL Server: Tutorials, blogs and other resources that you actually use or used in the past to improve your SQL Server skills.

As we all know when you google: "SQL Server" Tutorial you will get millions of results returned and it takes some effort to find something really interesting and worth spending your time on. The idea here is simple: Let's list websites, books, tutorials etc. that you actually use or used in the past. Something that you could truly reco...

User-Defined Functions SQL Server 2005 flagged incorrectly as non-deterministic?

Related to this question, I decided to check the UDFs in my data warehouse (which should largely have been deterministic), and I found several which aren't which should be. For instance: CREATE FUNCTION [udf_YearFromDataDtID] ( @DATA_DT_ID int ) RETURNS int AS BEGIN RETURN @DATA_DT_ID / 10000 END Shows up in this query: SELE...

SQL Server: Floor a date in SQL server, but stay deterministic

(This is related to Floor a date in SQL server.) Does a deterministic expression exist to floor a DATETIME? When I use this as a computed column formula: DATEADD(dd, DATEDIFF(dd, 0, [datetime_column]), 0) the I get an error when I place an index on that column: Cannot create index because the key column 'EffectiveDate' is non-det...

SQL 2005 Trigger Question

Can I ascertain the name of the stored procedure that caused the trigger to fire from within the trigger? ...

MySQL: How to ask for a date greater than today when a date is in a string

Hi, I'm try to extract info from a MySQL DB into a MS SQL DB. The DB is a mess and the developer is no longer available. All dates are in char fields, and I use SELECT concat( mid(DueDate, 7, 4), mid(DueDate, 4, 2), mid(DueDate, 1, 2)) as DueDate FROM TableName to get the date field in a format so MS sql server can import them. Now...

How to make conversions from varchar to datetime deterministic?

In the tradition of this question and in light of the documentation, how does one make this function deterministic: ALTER FUNCTION [udf_DateTimeFromDataDtID] ( @DATA_DT_ID int -- In form YYYYMMDD ) RETURNS datetime WITH SCHEMABINDING AS BEGIN RETURN CONVERT(datetime, CONVERT(varchar, @DATA_DT_ID)) END Or this one (because of t...

sql server set implicit_transactions off and other options

I am still learning sql server somewhat and recently came across a select query in a stored procedure which was causing a very slow fill of a dataset in c#. At first I thought this was to do with .NET but then found a suggestion to put in the stored procedure: set implicit_transactions off this seems to cure it but I would like to know...

How to make SQL Server running in Virtual PC accessible to host OS?

I'm running SQL Server 2008 Express on Windows XP on a VirtualPC instance inside a Windows XP host. I want to be able to connect to databases on the guest instance using SSMS on the host. When I go to connect from SSMS on the host, and browse for servers, I see the instance of SQL Server on the guest. Yet when I try to connect, using ...

SQL Server Weighted Full Text Search

Currently I have a table that I search upon 4 fields, FirstName, LastName, MiddleName, And AKA's. I currently have a CONTAINSTABLE search for the rows and it works. Not well but it works. Now I want to make the First Name weighted higher and middle name lower. I found the command ISABOUT but that seems pretty worthless if I have to do i...

Does query plan optimizer works well with joined/filtered table-valued functions?

In SQLSERVER 2005, I'm using table-valued function as a convenient way to perform arbitrary aggregation on subset data from large table (passing date range or such parameters). I'm using theses inside larger queries as joined computations and I'm wondering if the query plan optimizer work well with them in every condition or if I'm bett...

How do I select top 10 rows in a table without sorting?

I want to select the top 10 records from a table in SQL Server without arranging the table in ascending or descending order. ...

How do I select last 5 rows in a table without sorting?

I want to select the last 5 records from a table in SQL Server without arranging the table in ascending or descending order. ...

Using WITH NOLOCK Table Hint in Query Using View - Does it Propagate Within the View?

If a "WITH NOLOCK" query hint is used on a View in SQL Server, does it propagate that hint to the view definition itself, even if NOLOCK is NOT used for the raw tables in the View definition? The reason to need this is that sometimes the support staff wants to do huge time-consuming queries but would rather not force this lock on all que...