Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SET values

Author  Topic 

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-09-22 : 07:16:53
Hi,

Im trying to run the following:

declare @count1 varchar(max), @count2 varchar(max)
SET @count1 = select count(*) from purchase
SET @count2 = select max(purchase_count) from timestamptable

getting error for setting values count1 and 2.

How would I go about setting those values to what i want from the 2 tables?

Thanks

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-09-22 : 07:20:20
fixed it myself :)

quote:
Originally posted by cipriani1984

Hi,

Im trying to run the following:

declare @count1 varchar(max), @count2 varchar(max)
SET @count1 = select count(*) from purchase
SET @count2 = select max(purchase_count) from timestamptable

getting error for setting values count1 and 2.

How would I go about setting those values to what i want from the 2 tables?

Thanks

Go to Top of Page

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-09-22 : 07:38:22
actually no i didnt lol

Any help please?

quote:
Originally posted by cipriani1984

fixed it myself :)

quote:
Originally posted by cipriani1984

Hi,

Im trying to run the following:

declare @count1 varchar(max), @count2 varchar(max)
SET @count1 = select count(*) from purchase
SET @count2 = select max(purchase_count) from timestamptable

getting error for setting values count1 and 2.

How would I go about setting those values to what i want from the 2 tables?

Thanks



Go to Top of Page

sanoj_av
Posting Yak Master

118 Posts

Posted - 2009-09-22 : 07:55:47
Select @count1 = count(*) from purchase
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-22 : 09:32:50
quote:
Originally posted by cipriani1984

Hi,

Im trying to run the following:

declare @count1 varchar(max), @count2 varchar(max)
SET @count1 = select count(*) from purchase
SET @count2 = select max(purchase_count) from timestamptable

getting error for setting values count1 and 2.

How would I go about setting those values to what i want from the 2 tables?

Thanks


It should be

declare @count1 varchar(max), @count2 varchar(max)
SET @count1 = (select count(*) from purchase)
SET @count2 = (select max(purchase_count) from timestamptable)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-09-22 : 13:35:46
Actually, are your variables supposed to by VARCHAR or should they be INT?

declare @count1 varchar(max), @count2 varchar(max)
SET @count1 = CAST((select count(*) from purchase) AS VARCHAR(10))
SET @count2 = CAST((select max(purchase_count) from timestamptable) AS VARCHAR(10))

-- Or

declare @count1 INT, @count2 INT
SET @count1 = (select count(*) from purchase)
SET @count2 = (select max(purchase_count) from timestamptable)
Go to Top of Page
   

- Advertisement -