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

Ausgedruckt am: 28.03.2024 um 21:03 Uhr

Mitglied: SlainteMhath
SlainteMhath 05.10.2011 um 10:46:30 Uhr
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
Mitglied: ITSchlumpf
ITSchlumpf 05.10.2011 um 11:15:41 Uhr
Goto Top
Ahh cool das war die Lösung. Danke für die rasche Hilfe face-smile

Gruß
Schlumpf