SQL create table with filters
I have an autogenerated create table SQL statement from the import/export wizard. However, the the table I am creating from has too many rows, therefore I would like to import only after a certain date.
I have the following:
CREATE TABLE [DB1].[dbo].[Agent] (
[UserId] nvarchar(50) NOT NULL,
[StatusDateTime] datetime NOT NULL,
[StatusDateTimeGMT] datetime NOT NULL,
) where StatusDateTimeGMT >='2011-08-15'
When I try to add either a where clause with the StatusDateTimeGMT
field being >='2011-08-15', it throws me an error. I also tried using a CHECK constraint, but with no success. Any ideas?
Here is the error:
Error 0xc002f210: Preparation SQL Task: Executing the query
开发者_开发技巧 "CREATE TABLE [db1].[dbo].[Agent] ( [UserId] nvarchar(50) NOT NULL, [StatusDateTime] datetime NOT NULL, [StatusDateTimeGMT] datetime NOT NULL, )where StatusDateTimeGMT >='20110815' " failed with the following error: "Exception from HRESULT: 0x80040E14". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
I don't know if understood the question, but if you want to load the data that matches a certain parameter, you first create the table and then insert the data you want in it using a command similar to the following.
INSERT INTO [BD1].[dbo].[Agent]
SELECT [UserId], [StatusDateTime], [StatusDateTimeGMT]
FROM [sourceData]
WHERE StatusDateTimeGMT >='2011-08-15'
Just as an example.
精彩评论