SELECT DATEDIFF(day,FromDOS,ThruDOS) as LengthOfStay FROM tbl_Master
I want my new column to be added to the table I have queried. I have tried several coding options and scoured my SQL books to no avail. I know this must be simple. That is what makes it so frustrating.
Requires Free Membership to View
/****** Object: Table [dbo].[tbl_Master] Script Date: 5/9/2005 9:45:17 AM ******/ CREATE TABLE [dbo].[tbl_Master] ( [LOSID] [int] NOT NULL , [FromDOS] [datetime] NOT NULL , [ThruDOS] [datetime] NOT NULL , [LengthofStay] AS (datediff(day,[FromDos],[ThruDos])) ) ON [PRIMARY] GO ALTER TABLE [dbo].[tbl_Master] WITH NOCHECK ADD CONSTRAINT [PK_tbl_Master] PRIMARY KEY CLUSTERED ( [LOSID] ) ON [PRIMARY] GO
Here is a screen shot with the sample data:
Do you have comments on this Ask the Expert Q&A? Let us know.
This was first published in May 2005

Join the conversationComment
Share
Comments
Results
Contribute to the conversation