troubleshooting Question

Adding a default value to each row in a table variable

Avatar of cdemott33
cdemott33Flag for United States of America asked on
Microsoft SQL Server 2005Microsoft SQL Server 2008SQL
2 Comments1 Solution228 ViewsLast Modified:
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')
ASKER CERTIFIED SOLUTION
Aneesh
Database Consultant
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros