Adding a default value to each row in a table variable

cdemott33
cdemott33 used Ask the Experts™
on
I've created a table variable and stored some value within it.  There is a column in my table called  "clientName" . Here what I need to do.

I need to set the clientName column to have the default value of 'Apple' for each row in my table.

How can I do this?

	DECLARE @myTable table
	(
		myguid int identity(1,1),
		clientName nvarchar(50),
		transactionNumber int,
		jobNumber nvarchar(500),
		eventName nvarchar(500),
		location nvarchar(500),
		tier nvarchar(100),
		movein datetime,
		startdate datetime,
		endtime datetime,
		moveout datetime
	)
		
	INSERT INTO @myTable(
		transactionNumber,
		jobNumber,
		eventName,
		location,
		tier,
		movein,
		startdate,
		endtime,
		moveout
		)		
	SELECT   
		o.transactionNumber,  
		o.jobNumber, 
		o.eventName, 
		ei.location,  
		ei.tier,  
		o.shipToDeliveryDate,
		ei.startDate,
		ei.endDate,
		ei.tearDownDate
	FROM         
		onlineOrder AS o 
		INNER JOIN 
			eventInformation AS ei 
				ON o.jobNumber = ei.jobNumber
	WHERE     
		(o.shipToDeliveryDate > '1/1/2012')

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Database Consultant
Top Expert 2009
Commented:
INSERT INTO @myTable(
                                  ClientName,
            transactionNumber,
            jobNumber,
            eventName,
            location,
            tier,
            movein,
            startdate,
            endtime,
            moveout
            )            
      SELECT     'Apple',
            o.transactionNumber,  
            o.jobNumber,
            o.eventName,
            ei.location,  
            ei.tier,  
            o.shipToDeliveryDate,
            ei.startDate,
            ei.endDate,
            ei.tearDownDate
      FROM        
            onlineOrder AS o

Author

Commented:
That was easy!  Thank you!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial