Home Forums SQL Server 2005 T-SQL (SS2K5) Select statment problem in cursor using datetimes RE: Select statment problem in cursor using datetimes

  • Okay, so let us take another tact. Let us start with a table of customers across the US. You want a list of customers in California, for instance.

    Here is a simple table for this:

    create table dbo.Customer (

    CustomerID int identity(1,1),

    CustomerName varchar(50) not null,

    CustomerAddress varchar(50) not null,

    CustomerCity varchar(50) not null,

    CustomerState char(2) not null,

    CustomerZipCode varchar(10) not null

    );

    A set-based solution for finding all customers in California (CA):

    select

    CustomerID,

    CustomerName,

    CustomerAddress,

    CustomerCity,

    CustomerState,

    CustomerZipCode

    from

    dbo.Customer

    where

    CustomerState = 'CA';

    I'd write a cursor-based solution, but I sometimes have issues with posting code with variable declarations from work.