Updating values in a table based of table in another db

  • I have a situation where I have two copies of a database. One db with correct values in a column named 'amount' and one database with more current information but the old entries amounts are incorrect.

    I am trying to figure out how to update the amount field of the more current table with the amounts of the table from the older db. I was thinking of possibly joining the tables based on their primary key, but have not found a good example of this anywhere.

    I'm sorry for my ignorance but can you please direct me here?

  • If you want the best and the correct solution, post the structure of the tables and some sample data!!

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

  • or you can try like this:

    NEW OR your table is TAB1

    OLD OR the table with old values is TAB2

    the code should be like this:

    UPDATE TAB1

    SET new_amount = T2.old_amount

    FORM TAB1 T1, TAB2 T2

    WHERE T1.ID = T2.ID

    new amount is the column wher you want to update, so the old_amount is the column with old values of the amount!

    hoep it helps!

    :hehe:

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

  • UPDATE newTable

    SET amount = oldTable.Amount

    FROM [schema_name].[table_name] newTable INNER JOIN

    [database_name].[schema_name].[table_name] oldTable ON oldTable.ID = newTable.ID

    Atlantis Interactive - SQL Server Tools
    My blog[/url]
    Why I wrote a sql query analyzer clone

  • wow fast responses thanks, those examples are perfect.. is there any reson I would have a problem calling a KEY? for example I can select staff_id fine but I can not select staff_KEY it tells me anything with _KEY is not a valid column. And I am trying to join on a staff_KEY since nothing else is unique.

  • ahall13 (1/8/2009)


    wow fast responses thanks, those examples are perfect.. is there any reson I would have a problem calling a KEY? for example I can select staff_id fine but I can not select staff_KEY it tells me anything with _KEY is not a valid column. And I am trying to join on a staff_KEY since nothing else is unique.

    I told you for the best solution, you should post the structure of the tables and also some sample data!

    I'm sure that someone will post the best solution for you!

    :w00t:

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

  • Here is the table scripted, the only column I need is sheet_entry_KEY which I am joining on and amount.

    /****** Object: Table [dbo].[Sheet_Entry] Script Date: 01/09/2009 04:54:14 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Sheet_Entry](

    [sheet_entry_KEY] [int] NOT NULL,

    [row_version] [timestamp] NOT NULL,

    [update__staff_KEY] [int] NOT NULL,

    [update_date] [datetime] NOT NULL CONSTRAINT [DF_Sheet_Entry__update_date] DEFAULT (getdate()),

    [client_KEY] [int] NULL,

    [engagement_KEY] [int] NULL,

    [activity_KEY] [int] NULL,

    [entry_date] [smalldatetime] NULL,

    [staff_billing_rate_KEY] [int] NULL,

    [units] [decimal](9, 2) NULL,

    [unit_cost] [decimal](9, 4) NULL,

    [unit_price] [decimal](9, 4) NULL,

    [amount] [decimal](9, 2) NULL,

    [comment] [ntext] COLLATE Latin1_General_CI_AS NULL,

    [biller_note] [ntext] COLLATE Latin1_General_CI_AS NULL,

    [sheet_entry_type_KEY] [int] NOT NULL CONSTRAINT [DF_Sheet_Entry__sheet_entry_type_KEY] DEFAULT (1),

    [staff_KEY] [int] NULL,

    [sheet_date] [smalldatetime] NULL,

    [approved_date] [smalldatetime] NULL,

    [approved__staff_KEY] [int] NULL,

    [posted_date] [smalldatetime] NULL,

    [posted__staff_KEY] [int] NULL,

    [create_date] [datetime] NOT NULL CONSTRAINT [DF_Sheet_Entry__create_date] DEFAULT (getdate()),

    [project_KEY] [int] NULL,

    [task_KEY] [int] NULL,

    [calculated_amount] [decimal](9, 2) NULL,

    [amount_is_overridden] [bit] NOT NULL CONSTRAINT [DF_Sheet_Entry__amount_is_overridden] DEFAULT (0),

    [complete] AS (case when ([staff_KEY] is not null and [sheet_date] is not null and [client_KEY] is not null and [engagement_KEY] is not null and [activity_KEY] is not null and [entry_date] is not null and [units] is not null and [unit_cost] is not null and [unit_price] is not null and [amount] is not null and ([calculated_amount] is not null)) then (convert(bit,1)) else (convert(bit,0)) end),

    CONSTRAINT [PK_Sheet_Entry] PRIMARY KEY CLUSTERED

    (

    [sheet_entry_KEY] ASC

    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Database assigned primary key for this table.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'sheet_entry_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Version that changes each time there is a change to this row (for optimistic concurrency).' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'row_version'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Key of the Staff who last modified this row.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'update__staff_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The date and time this row was last modified.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'update_date'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Key to the Client that this entry is for. The client must be the client of the Engagement.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'client_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Key to the Engagement this entry is for.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'engagement_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Key to the Activity this entry is for.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'activity_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date this entry is for.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'entry_date'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Key to the Staff Billing Rate used to calculate the amount.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'staff_billing_rate_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Quantity of units (or hours).' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'units'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Cost per unit (or hour) at the time the amount was computed.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'unit_cost'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Price per unit (or hour) at the time the amount was computed. Storage is required because amount can be rounded.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'unit_price'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Overridden extended price after computation and rounding.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'amount'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'An optional comment.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'comment'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'An optional comment for the biller.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'biller_note'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Key to Sheet Entry Type indicating what type of entry this is.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'sheet_entry_type_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Staff this Sheet Entry is for.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'staff_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date of the Sheet, also known as control date.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'sheet_date'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date this item was approved.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'approved_date'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Key of the Staff who approved this item.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'approved__staff_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date this item was posted.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'posted_date'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Key of the Staff who posted this item.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'posted__staff_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The date and time that this row was created.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'create_date'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Optionally links this Sheet Entry to a Project.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'project_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Optionally links this Sheet Entry to a Task.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'task_KEY'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Calculated extended price after computation and rounding.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'calculated_amount'

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'True when the calculated_amount is overridden and is necessary so that the override is not deleted if the values happen to match later.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'COLUMN', @level2name=N'amount_is_overridden'

    GO

    USE [CSP_0_Sample]

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [FK_Sheet_Entry__Activity__activity_KEY] FOREIGN KEY([activity_KEY])

    REFERENCES [dbo].[Activity] ([activity_KEY])

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [FK_Sheet_Entry__Client__client_KEY] FOREIGN KEY([client_KEY])

    REFERENCES [dbo].[Client] ([client_KEY])

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [FK_Sheet_Entry__Engagement__engagement_KEY__client_KEY] FOREIGN KEY([engagement_KEY], [client_KEY])

    REFERENCES [dbo].[Engagement] ([engagement_KEY], [client_KEY])

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [FK_Sheet_Entry__Project__project_KEY__engagement_KEY] FOREIGN KEY([project_KEY], [engagement_KEY])

    REFERENCES [dbo].[Project] ([project_KEY], [engagement_KEY])

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [FK_Sheet_Entry__Sheet_Entry_Type__sheet_entry_type_KEY] FOREIGN KEY([sheet_entry_type_KEY])

    REFERENCES [dbo].[Sheet_Entry_Type] ([sheet_entry_type_KEY])

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [FK_Sheet_Entry__Staff__approved__staff_KEY] FOREIGN KEY([approved__staff_KEY])

    REFERENCES [dbo].[Staff] ([staff_KEY])

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [FK_Sheet_Entry__Staff__posted__staff_KEY] FOREIGN KEY([posted__staff_KEY])

    REFERENCES [dbo].[Staff] ([staff_KEY])

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [FK_Sheet_Entry__Staff__staff_KEY] FOREIGN KEY([staff_KEY])

    REFERENCES [dbo].[Staff] ([staff_KEY])

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [FK_Sheet_Entry__Staff_Billing_Rate__staff_billing_rate_KEY] FOREIGN KEY([staff_billing_rate_KEY])

    REFERENCES [dbo].[Staff_Billing_Rate] ([staff_billing_rate_KEY])

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [FK_Sheet_Entry__Task__task_KEY__project_KEY] FOREIGN KEY([task_KEY], [project_KEY])

    REFERENCES [dbo].[Task] ([task_KEY], [project_KEY])

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [CK_Sheet_Entry__approved__staff_KEY] CHECK (([approved_date] is null and [approved__staff_KEY] is null or [staff_KEY] is not null and [sheet_date] is not null and [client_KEY] is not null and [engagement_KEY] is not null and [activity_KEY] is not null and [entry_date] is not null and [units] is not null and [unit_cost] is not null and [unit_price] is not null and [amount] is not null and [approved_date] is not null and [approved__staff_KEY] is not null))

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Can only be approved if it is complete and has no running timers.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'CONSTRAINT', @level2name=N'CK_Sheet_Entry__approved__staff_KEY'

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [CK_Sheet_Entry__approved_date] CHECK (([approved_date] is null or [approved_date] >= convert(datetime,'1900-01-01') and [approved_date] < convert(datetime,'2079-01-01') and datepart(hour,[approved_date]) = 0 and datepart(minute,[approved_date]) = 0 and datepart(second,[approved_date]) = 0 and datepart(millisecond,[approved_date]) = 0))

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date only and within valid range.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'CONSTRAINT', @level2name=N'CK_Sheet_Entry__approved_date'

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [CK_Sheet_Entry__calculated_amount] CHECK (([calculated_amount] is null and [amount] is null or [calculated_amount] is not null and [amount] is not null))

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'If amount is filled in then calculated_amount must also be filled in.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'CONSTRAINT', @level2name=N'CK_Sheet_Entry__calculated_amount'

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [CK_Sheet_Entry__entry_date] CHECK (([entry_date] is null or [entry_date] >= convert(datetime,'1900-01-01') and [entry_date] < convert(datetime,'2079-01-01') and datepart(hour,[entry_date]) = 0 and datepart(minute,[entry_date]) = 0 and datepart(second,[entry_date]) = 0 and datepart(millisecond,[entry_date]) = 0))

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date only and within valid range.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'CONSTRAINT', @level2name=N'CK_Sheet_Entry__entry_date'

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [CK_Sheet_Entry__posted__staff_KEY] CHECK (([posted_date] is null and [posted__staff_KEY] is null or [approved_date] is not null and [posted_date] is not null and [posted__staff_KEY] is not null))

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Can only be posted if it is approved.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'CONSTRAINT', @level2name=N'CK_Sheet_Entry__posted__staff_KEY'

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [CK_Sheet_Entry__posted_date] CHECK (([posted_date] is null or [posted_date] >= convert(datetime,'1900-01-01') and [posted_date] < convert(datetime,'2079-01-01') and datepart(hour,[posted_date]) = 0 and datepart(minute,[posted_date]) = 0 and datepart(second,[posted_date]) = 0 and datepart(millisecond,[posted_date]) = 0))

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date only and within valid range.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'CONSTRAINT', @level2name=N'CK_Sheet_Entry__posted_date'

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [CK_Sheet_Entry__sheet_date] CHECK (([sheet_date] is null or [sheet_date] >= convert(datetime,'1900-01-01') and [sheet_date] < convert(datetime,'2079-01-01') and datepart(hour,[sheet_date]) = 0 and datepart(minute,[sheet_date]) = 0 and datepart(second,[sheet_date]) = 0 and datepart(millisecond,[sheet_date]) = 0))

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date only and within valid range.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'CONSTRAINT', @level2name=N'CK_Sheet_Entry__sheet_date'

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [CK_Sheet_Entry__sheet_entry_KEY] CHECK (([sheet_entry_KEY] > 0))

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Sheet entry key must be greater than zero.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'CONSTRAINT', @level2name=N'CK_Sheet_Entry__sheet_entry_KEY'

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [CK_Sheet_Entry__sheet_entry_type_KEY] CHECK (((((not([sheet_entry_type_KEY] = 3 or [sheet_entry_type_KEY] = 2))) or ([sheet_entry_type_KEY] = 3 or [sheet_entry_type_KEY] = 2) and [amount] = 0.00 and [calculated_amount] = 0.00 and [units] = 0.00) and [amount] >= 0.00 and [calculated_amount] >= 0.00 and [unit_cost] >= 0 and [unit_price] >= 0 and [units] >= 0.00))

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Progress Billing and Billing Adjustment Sheet_Entry records must have amount and units set to zero since these are only placeholders used by Billing_Decision records. All other records must have amount, calculated_amount, unit_cost, unit_price, and units greater than or equal to zero.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'CONSTRAINT', @level2name=N'CK_Sheet_Entry__sheet_entry_type_KEY'

    GO

    ALTER TABLE [dbo].[Sheet_Entry] WITH CHECK ADD CONSTRAINT [CK_Sheet_Entry__staff_billing_rate_KEY] CHECK (([dbo].[sf_Rate_Staff_Activity_Date_Match]([staff_billing_rate_KEY], [staff_KEY], [activity_KEY], [entry_date]) is null))

    GO

    EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'staff_KEY, staff_billing_rate_KEY, activity_KEY and entry_date must have compatible values.' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'Sheet_Entry', @level2type=N'CONSTRAINT', @level2name=N'CK_Sheet_Entry__staff_billing_rate_KEY'

    Here are two rows of data

    2535 4887 5/8/2007 10:13:12 AM 1437 532 1018 1/3/2008 12:00:00 AM NULL 8.00 60.0000 0.0000 0.00 Company Holiday NULL 1 1552 1/3/2008 12:00:00 AM 7/21/2008 12:00:00 AM 4887 7/21/2008 12:00:00 AM 4887 5/8/2007 10:13:12 AM NULL NULL 0.00 False True

    2536 4887 5/8/2007 10:13:12 AM 1437 532 1018 1/3/2008 12:00:00 AM NULL 8.00 55.0000 0.0000 0.00 New Year's Holiday NULL 1 4885 1/3/2008 12:00:00 AM 7/21/2008 12:00:00 AM 4887 7/21/2008 12:00:00 AM 4887 5/8/2007 10:13:12 AM NULL NULL 0.00 False True

    my question is why won't this simple query work?

    Select amount

    from Sheet_Entry

    where sheet_entry_KEY = '2535'

  • sorry guys dumb error it needed to be

    Select amount

    from Sheet_Entry

    where [sheet_entry_KEY] = '2569'

    silly brackets

    thanks for your help I'm sure it should work now I just need to get to the data.

  • Did you try the 2 little code above!?

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply