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 |
|
companionz
Yak Posting Veteran
54 Posts |
Posted - 2009-04-16 : 09:22:44
|
| Guys,I want to pass a string to a procedure but don't know how to go about that..IN the below proc, i want to pass:@AssetGrupName = 'TESTING'@SerialNumber = '123AFSDF','23423ASDF','343234ASD'How to execute this proc now?This way i tried:AssetToAssetGroup 'TESTING', ''123AFSDF','23423ASDF','343234ASD''But it doesn't work..Procedure body:ALTER PROCEDURE AssetToAssetGroup @AssetGrupName VarChar(15), @SerialNumber VarChar(500)ASDeclare @AssetUid Int, @AssetGroupUid Int, @CompanyUid Int, @RowNum Int, @count intBEGIN Create table #tempTest ( AssetGroupUid varchar, AssetUid varchar, AssetGroupAssetUid int ) If Not Exists (Select * From assetGroup Where groupname = @AssetGrupName) BEGIN print 1 Return END Select @CompanyUid=CompanyUid, @AssetGroupUid=AssetGroupUid From assetGroup where groupname = @AssetGrupName If Not Exists (Select * From Asset Where CompanyUid=@CompanyUid and DeviceSerialNumber in (@SerialNumber)) BEGIN print 2 Return END Declare Cur_GetUid CURSOR FOR Select Uid, row_number() over (order by Uid ) As RowNumber From Asset Where CompanyUid=@CompanyUid and DeviceSerialNumber in (@SerialNumber) Open Cur_GetUid Fetch Next From Cur_GetUid Into @AssetUid, @RowNum; WHILE @@FETCH_STATUS = 0 BEGIN IF @@FETCH_STATUS <> -2 BEGIN If Not Exists (Select * From AssetGroupAsset Where AssetGroupUid=@AssetGroupUid And AssetUid=@AssetUid) Insert #tempTest (AssetGroupUid, AssetUid, AssetGroupAssetUid) Values (@AssetGroupUid, @AssetUid, @RowNum) print 3 Fetch Next From Cur_GetUid Into @AssetUid, @RowNum; END Close Cur_GetUid DeAllocate Cur_GetUid Select * from #TempTest END ENDGuys, please help out.. Thanks,Sourav |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-04-16 : 09:31:09
|
| Firstly, you do not need a cursor to do this, all you are going to do is slow down the procedure. Secondly, do a search on this site for a PARSE function as you need this to split your results to be read by your in clause. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-16 : 09:36:54
|
| or search for Array+SQL Server in googleMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|