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.
| Author |
Topic |
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2007-07-06 : 21:19:14
|
| /*I have a table with random values*/declare @Tmp(Val varchar(30))insert into @Tmp(val)select 'fadsfadfada'union allselect 'fadsfdfaa'union allselect 'fadsfsfda'union allselect 'fadr32fda'/*so now I have 4 unique valuesWhat I want to do is pass a variable containing a integer*/declare @Myint intset @MyInt = 13321/* I then want to select all records in @Tmp order alpha and # according to MyInt*//*'fadsfadfada',13321'fadsfdfaa',13322'fadsfsfda',13323'fadt32fda',13324I was thinking of doing this with a identity column and just reseeding it each time, but I was hoping there was a better way*/ |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2007-07-06 : 21:43:48
|
| I just settled on doing thisDeclare @MyInt intset @MyInt = 12312set @MyInt = @Myint - 1select *,@MyInt + (Select Count(*) from @Tmp b where b.val <= a.Val)from @Tmp a |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-07-06 : 22:33:35
|
[code]DECLARE @Tmp TABLE (Val varchar(30))INSERT INTO @Tmp(Val)SELECT 'fadsfadfada' UNION ALLSELECT 'fadsfdfaa' UNION ALLSELECT 'fadsfsfda' UNION ALLSELECT 'fadr32fda'DECLARE @MyInt intSET @MyInt = 13321SELECT Val, @MyInt + (row_number() OVER( ORDER BY Val)) - 1FROM @Tmp[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2007-07-06 : 22:38:47
|
Can I use that method when I have a lot of criteria. Here is my exact query I am using nowUpdate aset a.CheckNo = @StartingCheckNo + (select count(*) from TSTD_ShortTermDisabilityCheck aa Inner Join TSTD_SHortTermDisability bb on aa.ShortTermDisabilityID = bb.ShortTermDisabilityID where bb.BenefitTypeID = b.BenefitTypeID and aa.ShortTermDisabilityCheckID <= a.ShortTermDisabilityCheckID and aa.checkStatusID = a.CheckStatusID)from TSTD_ShortTermDisabilityCheck ainner Join TSTD_SHortTermDisability bon a.ShortTermDisabilityID = b.ShortTermDisabilityID where b.BenefitTypeID = 2 and a.CheckStatusID = 2 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-06 : 23:12:58
|
| Yes you can make use of Row_number() functionAlso where do you want to show data?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|