| Author |
Topic |
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2007-11-15 : 15:15:38
|
| Hi I'm fairly new T-sql, I've produced a stored procedure to run two different 'Select' statements depending on the parameter entered, but I cannot get the script to work.The script is as follows:CREATE PROCEDURE usp_ECG_CallLogByVenueORBB (@inVAr int)ASIF (@inVAr = 0) THENBEGINSELECT 0 ,b.Username,b.Forename,b.Surname,cl.Extension,cl.CallTime,cl.CallType,cl.CallNumber,cl.CallCost,cl.CallDuration,cl.EXT2,cl.DDIFROM [EC.CallInfo] cl INNER JOIN tblBod AS b ON cl.CallNumber = b.PhoneUNION ALLSELECT0 ,b1.username,b1.forename ,b1.surname,cl1.Extension,cl1.CallTime,cl1.CallType,cl1.CallNumber,cl1.CallCost,cl1.CallDuration,cl1.EXT2,cl1.DDIFROM [EC.CallLogs] AS cl1 INNER JOIN tblBod AS b1 ON cl1.CallNumber = b1.MobileIF (@inVAr = 1) THENBEGINSELECT1,ven.VenueID ,ven.[Name] ,ven.ContactName ,cl.Extension,cl.CallTime,cl.CallType,cl.CallNumber,cl.CallCost,cl.CallDuration,cl.EXT2,cl.DDIFROM [EC.CallLogs] AS clINNER JOIN tblVenue AS ven ON cl.CallNumber = ven.TelephoneGODoes anyone know what ther errors are?Thanks |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-11-15 : 15:18:01
|
| Your IF statements aren't formed correctly. You are missing END statements.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2007-11-15 : 15:28:50
|
| As in?CREATE PROCEDURE usp_ECG_CallLogByVenueORBB (@inVAr int)ASIF (@inVAr = 0) THENBEGINSELECT0 ,b.Username,b.Forename,b.Surname,cl.Extension,cl.CallTime,cl.CallType,cl.CallNumber,cl.CallCost,cl.CallDuration,cl.EXT2,cl.DDIFROM [EC.CallInfo] cl INNER JOIN tblBod AS b ON cl.CallNumber = b.PhoneUNION ALLSELECT0 ,b1.username,b1.forename ,b1.surname,cl1.Extension,cl1.CallTime,cl1.CallType,cl1.CallNumber,cl1.CallCost,cl1.CallDuration,cl1.EXT2,cl1.DDIFROM [EC.CallLogs] AS cl1 INNER JOIN tblBod AS b1 ON cl1.CallNumber = b1.MobileENDIF (@inVAr = 1) THENBEGINSELECT1,ven.VenueID ,ven.[Name] ,ven.ContactName ,cl.Extension,cl.CallTime,cl.CallType,cl.CallNumber,cl.CallCost,cl.CallDuration,cl.EXT2,cl.DDIFROM [EC.CallLogs] AS clINNER JOIN tblVenue AS ven ON cl.CallNumber = ven.TelephoneEND |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-11-15 : 15:30:55
|
| Remove "THEN" from your code. Also read up on how to construct proper IF statements in SQL Server Books Online. This is very basic syntax.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
|
|
|