September 14, 2010 at 10:05 am
I am in the process of creating some test data which will include NULL values. I looked around for some guidance but was not able to find anything that would help.
Anyway, here is what I have inculding where I need the NULL values:
IF OBJECT_ID(N'VC') IS NOT NULL
DROP TABLE VC
GO
CREATE TABLE vc
(
case_sk int NOT NULL,
case_number varchar(15) NULL,
datereceived datetime NULL,
closeddate datetime NULL,
cc_init varchar(3) NULL,
atty_inits varchar(3) NULL
)
GO
INSERT INTO VC (case_sk, case_number, datereceived, closeddate, cc_inits, atty_inits )
SELECT 00001, 000001, '9/1/2006', '9/1/20009', 'AA1', 'BBB' UNION ALL
SELECT 00002, 000002, '9/1/2008', '9/1/20010', NULL, 'EEE' UNION ALL
SELECT 00003, 000003, '10/1/2008', '9/1/2009', 'BB2', 'AAA' UNION ALL
SELECT 00004, 000004, '1/1/2007', '9/1/2010', NULL, 'CCC' UNION ALL
SELECT 00005, 000005, '2/1/2007', NULL, NULL, 'BBB' UNION ALL
SELECT 00006, 000006, '3/1/2009', '9/1/2009', 'AA1', 'CCC' UNION ALL
SELECT 00007, 000007, '2/1/2009', '9/1/2009', NULL, 'DDD' UNION ALL
SELECT 00008, 000008, '2/1/2009', '6/1/2010', 'AA1', 'DDD' UNION ALL
SELECT 00009, 000009, '5/1/2010', '9/1/2010', 'BB2' 'EEE' UNION ALL
SELECT 00010, 000010, '5/1/2010', NULL, NULL, 'EEE' UNION ALL
SELECT 00011, 000011, '6/1/2010', NULL, NULL, 'EEE'
--DROP TABLE VC
SELECT vc.case_sk, vc.datereceived, vc.closeddate, ISNULL(vc.cc_inits, vc.atty_inits) AS Intials,
vc.case_number
FROM vc
GROUP BY vc.case_sk, vc.datereceived, vc.closeddate, ISNULL(vc.cc_inits, vc.atty_inits),
vc.case_number
Thanks in advance!
September 14, 2010 at 10:11 am
Paul, i dint quite understand ur requirement.. did u mean, u need to hardcode a column as NULL in the SELECT ?
September 14, 2010 at 10:22 am
Sorry for the confusion...
Where the NULL values are in the Insert, those are supposed to be blank... E.I. no closed date or cc_initials.
September 14, 2010 at 10:26 am
Then why not include a blank there? I'm still not clear what you are trying to do.
September 14, 2010 at 10:29 am
for case_sk = 000009, there is no comma between the cc_init and atty_inits.
Also, in some places you have cc_init, and in others cc_inits.
That should get your test data loaded.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
September 14, 2010 at 10:36 am
Steve Jones - Editor (9/14/2010)
Then why not include a blank there? I'm still not clear what you are trying to do.
I get syntax errors when I do blanks:
INSERT INTO VC (case_sk, case_number, datereceived, closeddate, cc_inits, atty_inits )
SELECT 00001, 000001, '9/1/2006', '9/1/20009', 'AA1', 'BBB' UNION ALL
SELECT 00002, 000002, '9/1/2008', '9/1/20010', , 'EEE' UNION ALL
SELECT 00003, 000003, '10/1/2008', '9/1/2009', 'BB2', 'AAA' UNION ALL
SELECT 00004, 000004, '1/1/2007', '9/1/2010', , 'CCC' UNION ALL
SELECT 00005, 000005, '2/1/2007', , , 'BBB' UNION ALL
SELECT 00006, 000006, '3/1/2009', '9/1/2009', 'AA1', 'CCC' UNION ALL
SELECT 00007, 000007, '2/1/2009', '9/1/2009', , 'DDD' UNION ALL
SELECT 00008, 000008, '2/1/2009', '6/1/2010', 'AA1', 'DDD' UNION ALL
SELECT 00009, 000009, '5/1/2010', '9/1/2010', 'BB2', 'EEE' UNION ALL
SELECT 00010, 000010, '5/1/2010', , , 'EEE' UNION ALL
SELECT 00011, 000011, '6/1/2010', , , 'EEE'
September 14, 2010 at 10:39 am
Well that explains part of it....
I am still getting an error:
Conversion falied when converting date and/or time for character string
I assume that is the NULL being read in as a string into the datetime column... That is where I am stuck.
September 14, 2010 at 11:01 am
Paul Morris-1011726 (9/14/2010)
Well that explains part of it....I am still getting an error:
Conversion falied when converting date and/or time for character string
I assume that is the NULL being read in as a string into the datetime column... That is where I am stuck.
The first two selects have 5 digit years...
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
September 14, 2010 at 12:02 pm
My apologies for being a bonehead....
Thanks WayneS
September 14, 2010 at 1:09 pm
Paul Morris-1011726 (9/14/2010)
My apologies for being a bonehead....Thanks WayneS
No problem - we all do it time to time.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply