Question : Access SQL If .. Else

HI all,

I have a Stored Procedure in SQL2005 but I want to convert it to an Access query.
Only I can't get it to work. Can anyone give me an example of how to convert this SP to an Access query?
Thx for the help!

IF @wrf_id > 0
      SELECT [wrf_id]
      ,[wrf_naam]+ ' ' + isnull([wrf_voorNaam],'') as volNaam
        ,[wrf_naam]
      ,[wrf_voorNaam]
      ,[wrf_straat]+ ' ' + cast([wrf_huisNr]as varchar(5))+ ',' + ' ' + [wrf_postCode] + ' '+ [wrf_gemeente] as adres
        ,[wrf_straat]
      ,[wrf_huisNr]
      ,[wrf_busNr]
      ,[wrf_postCode]
      ,[wrf_gemeente]
      ,[wrf_land]
      ,[wrf_cnt_id]
  FROM [ft_one].[dbo].[ft_werf]
  WHERE wrf_id = @wrf_id

ELSE
      SELECT [wrf_id]
      ,[wrf_naam]+ ' ' + isnull([wrf_voorNaam],'') as volNaam
        ,[wrf_naam]
      ,[wrf_voorNaam]
      ,[wrf_straat]+ ' ' + cast([wrf_huisNr]as varchar(5))+ ',' + ' ' + [wrf_postCode] + ' '+ [wrf_gemeente] as adres
        ,[wrf_straat]
      ,[wrf_huisNr]
      ,[wrf_busNr]
      ,[wrf_postCode]
      ,[wrf_gemeente]
      ,[wrf_land]
      ,[wrf_cnt_id]
  FROM [ft_one].[dbo].[ft_werf]
  ORDER BY adres ASC
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
IF @wrf_id > 0
	SELECT [wrf_id]
      ,[wrf_naam]+ ' ' + isnull([wrf_voorNaam],'') as volNaam
	  ,[wrf_naam]
      ,[wrf_voorNaam]
      ,[wrf_straat]+ ' ' + cast([wrf_huisNr]as varchar(5))+ ',' + ' ' + [wrf_postCode] + ' '+ [wrf_gemeente] as adres
	  ,[wrf_straat]
      ,[wrf_huisNr]
      ,[wrf_busNr]
      ,[wrf_postCode]
      ,[wrf_gemeente]
      ,[wrf_land]
      ,[wrf_cnt_id]
  FROM [ft_one].[dbo].[ft_werf]
  WHERE wrf_id = @wrf_id
 
ELSE
	SELECT [wrf_id]
      ,[wrf_naam]+ ' ' + isnull([wrf_voorNaam],'') as volNaam
	  ,[wrf_naam]
      ,[wrf_voorNaam]
      ,[wrf_straat]+ ' ' + cast([wrf_huisNr]as varchar(5))+ ',' + ' ' + [wrf_postCode] + ' '+ [wrf_gemeente] as adres
	  ,[wrf_straat]
      ,[wrf_huisNr]
      ,[wrf_busNr]
      ,[wrf_postCode]
      ,[wrf_gemeente]
      ,[wrf_land]
      ,[wrf_cnt_id]
  FROM [ft_one].[dbo].[ft_werf]
  ORDER BY adres ASC

Answer : Access SQL If .. Else

since there is no flow control in access sql (like if-else), you can't.
you can build 2 queries for the 2 select statements and have the if-then reside in vb code before calling them

or, since the First query is a subset of the second (same data only filtered by the where clause) you can have only the second query (no where clause) saved, then show the results in a form with it's open event set to:
IF (somevariable) > 0 Then
    Me.Filter="wrf_id = " & (somevariable)
    Me.FilterOn=True
End If
Random Solutions  
 
programming4us programming4us