itschlumpf
Goto Top

SQL Abfrage mit einem Rückgabewert

Hallo zusammen,

ich habe ein kleines Problem und bräucht dringend eure Hilfe.

Ich hab eine SQL-Abfrage welche mir einen Rückgabewert zurück geben soll. Die frage ist jetzt allerdings wie bekomm ich den rückgabewert.

Ich habe auf der Microsoft Seite mal folgenden Ansatz gefunden.

Set @Count = N'(Select count(*) From bcptest.dbo.t1 Where Barcode = ''1234'')';  
   Exec sp_executesql @count, @Output1 Output

if @Output1 != 0 
Begin

Mach irgendwas

End

Leider wird nichts in die Output Variable geschrieben. Könnt ihr mir da bitte helfen?

Gruß
Schlumpf

[Edit] Die Variablen sind nvarchars [/Edit]

Content-Key: 174148

Url: https://administrator.de/contentid/174148

Printed on: April 24, 2024 at 02:04 o'clock

Member: SlainteMhath
SlainteMhath Oct 05, 2011 at 08:46:30 (UTC)
Goto Top
Moin,

Du kannst im SELECT direkt Variablen befüllen:

Select @OutputCount=count(*) From bcptest.dbo.t1 Where Barcode = '1234'  
if @OutputCount != 0  [...]

lg,
Slainte
Member: ITSchlumpf
ITSchlumpf Oct 05, 2011 at 09:15:41 (UTC)
Goto Top
Ahh cool das war die Lösung. Danke für die rasche Hilfe face-smile

Gruß
Schlumpf