Transact SQL :: Getting Syntax Errors In Where Statement

Oct 9, 2015

I've created multiple select statement to pull in varies fields from a table and one of those fields is Fiscal_Year, however, after the select statement I'm adding a Where clause:

Where Fiscal_Year = '2013'

And I keep getting a syntax error??

View 3 Replies


ADVERTISEMENT

Incorrect Syntax When There Appears To Be No Syntax Errors.

Dec 14, 2003

I keep receiving the following error whenever I try and call this function to update my database.

The code was working before, all I added was an extra field to update.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'


Public Sub MasterList_Update(sender As Object, e As DataListCommandEventArgs)

Dim strProjectName, txtProjectDescription, intProjectID, strProjectState as String
Dim intEstDuration, dtmCreationDate, strCreatedBy, strProjectLead, dtmEstCompletionDate as String

strProjectName = CType(e.Item.FindControl("txtProjectName"), TextBox).Text
txtProjectDescription = CType(e.Item.FindControl("txtProjDesc"), TextBox).Text
strProjectState = CType(e.Item.FindControl("txtStatus"), TextBox).Text
intEstDuration = CType(e.Item.FindControl("txtDuration"), TextBox).Text
dtmCreationDate = CType(e.Item.FindControl("txtCreation"),TextBox).Text
strCreatedBy = CType(e.Item.FindControl("txtCreatedBy"),TextBox).Text
strProjectLead = CType(e.Item.FindControl("txtLead"),TextBox).Text
dtmEstCompletionDate = CType(e.Item.FindControl("txtComDate"),TextBox).Text
intProjectID = CType(e.Item.FindControl("lblProjectID"), Label).Text

Dim strSQL As String
strSQL = "Update tblProject " _
& "Set strProjectName = @strProjectName, " _
& "txtProjectDescription = @txtProjectDescription, " _
& "strProjectState = @strProjectState, " _
& "intEstDuration = @intEstDuration, " _
& "dtmCreationDate = @dtmCreationDate, " _
& "strCreatedBy = @strCreatedBy, " _
& "strProjectLead = @strProjectLead, " _
& "dtmEstCompletionDate = @dtmEstCompletionDate, " _
& "WHERE intProjectID = @intProjectID"

Dim myConnection As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("connectionstring"))
Dim cmdSQL As New SqlCommand(strSQL, myConnection)

cmdSQL.Parameters.Add(new SqlParameter("@strProjectName", SqlDbType.NVarChar, 40))
cmdSQL.Parameters("@strProjectName").Value = strProjectName
cmdSQL.Parameters.Add(new SqlParameter("@txtProjectDescription", SqlDbType.NVarChar, 30))
cmdSQL.Parameters("@txtProjectDescription").Value = txtProjectDescription
cmdSQL.Parameters.Add(new SqlParameter("@strProjectState", SqlDbType.NVarChar, 30))
cmdSQL.Parameters("@strProjectState").Value = strProjectState
cmdSQL.Parameters.Add(new SqlParameter("@intEstDuration", SqlDbType.NVarChar, 60))
cmdSQL.Parameters("@intEstDuration").Value = intEstDuration
cmdSQL.Parameters.Add(new SqlParameter("@dtmCreationDate", SqlDbType.NVarChar, 15))
cmdSQL.Parameters("@dtmCreationDate").Value = dtmCreationDate
cmdSQL.Parameters.Add(new SqlParameter("@strCreatedBy", SqlDbType.NVarChar, 10))
cmdSQL.Parameters("@strCreatedBy").Value = strCreatedBy
cmdSQL.Parameters.Add(new SqlParameter("@strProjectLead", SqlDbType.NVarChar, 15))
cmdSQL.Parameters("@strProjectLead").Value = strProjectLead
cmdSQL.Parameters.Add(new SqlParameter("@dtmEstCompletionDate", SqlDbType.NVarChar, 24))
cmdSQL.Parameters("@dtmEstCompletionDate").Value = dtmEstCompletionDate
cmdSQL.Parameters.Add(new SqlParameter("@intProjectID", SqlDbType.NChar, 5))
cmdSQL.Parameters("@intProjectID").Value = intProjectID

myConnection.Open()
cmdSQL.ExecuteNonQuery
myConnection.Close()

MasterList.EditItemIndex = -1
BindMasterList()


End Sub

Thankyou in advance.

View 3 Replies View Related

Syntax Errors In SP!

Nov 30, 2005

Hi Dears Below is the Sp that i want to use but there are many Syntax erros plz verify and correct them Thnx

create procedure CheckStatus

@EmpID int
as
-- i need some variables so i declared them
declare @ShiftId int
declare @DayTime smalldatetime
declare @ShiftStartT smalldatetime
declare @ShiftEndT smalldatetime
declare @ShiftInOutStatus int
declare @ShiftValidity bit
declare @RTValue int


-- Now i m assigning the values to the declared variable by selecting some value from tables
-- from this point i m having syntax erroes i dont know what are they all atables and all fields are ok verified

set @ShiftId=SELECT S_Id FROM Emp_Info WHERE Emp_Info.Emp_Id=@EmpID
set @DayTime=SELECT GETDATE()
set @ShiftStartT=SELECT S_ST FROM Emp_Shift WHERE Emp_Shift.S_Id=@ShiftId
set @ShiftEndT=SELECT S_ET FROM Emp_Shift WHERE Emp_Shift.S_Id=@ShiftId
set @InOutStatus=SELECT IOStatus FROM Emp_Status WHERE Emp_Status.Emp_Id=@EmpId
-- here i m using a nested case for some checks to insert values into tables
CASE -- Main Case
WHEN @InOutStatus=0 OR @InOutStatus=-1
-- Calling udf_IsShiftValid(datetime,datetime,datetime) a function that ia also ok and returns two possible value 0 or 1
THEN @ShiftValidty=udf_IsShiftValid(@ShiftStartT,@ShiftEndT,@DayTime)
CASE --nested case starts here
WHEN @ShiftValidity=1-- Insertin value into Emp_Status table and assihning value to @RTValue
THEN (INSERT INTO Emp_Status(IOStatus) VALUES(@ShiftValidity) WHERE Emp_Status.Emp_Id=@EmpID
SET @RTValue=1)
WHEN @ShiftValidity=0 THEN SET @RTValue=-1
END-- Nested case End Here
WHEN @InOutStatus=1
THEN
INSERT INTO Emp_Status(IOStatus) VALUES(0) WHERE Emp_Status.Emp_Id=@EmpID
SET @RTValue=0
END

RETURN @RTValue

GO

View 5 Replies View Related

Syntax Errors

Mar 25, 2008

This is my code

Select Sum(Cost) as Cost, Case When PymtRmID = 'Net 10' then (TodaysDate)+10 else pymtrmid end
From #ttNonWires
Group By Case When PymtRmID = 'Net 10' then (TodaysDate)+10 else pymtrmid end

Im trying to show obviousally when something when PYMTRMID says net10 i want todaydate +10 days in the column next to it i keep getting

Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.

View 1 Replies View Related

Problems With Sp_executesql - Syntax Errors

Jun 7, 2005

I tried doing a search on the forums, but it kept giving me the message: XXX is used too often and is excluded from your search


Anyway, here is the code:


Code:


DECLARE @Test nVarchar(10)
DECLARE @Test1 nVarchar(40)

SET @Test = N'''1'',''3'',''4'''

SET @Test1 = N'select * from table1 where column1 in (' + @Test + ')'

EXEC sp_executesql @Test1



If I put it in a "Begin Transaction" block

there is a syntax error near the ( in the set @Test1 statement.

If I leave it out of a "Begin Transaction" Block,

The syntax error is:

Server: Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark before the character string ''.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ''.

View 1 Replies View Related

Stored Procedure T -sql Syntax Errors

Apr 22, 2008



Hi, i'm writing this stored procedure -




Code Snippet
USE [TheHub]
GO

create proc dbo.sp_GetInvitationsHistoryDetails(@ExecID int, @OrgID int)
as
IF (@OrgID = 0)
BEGIN
select E.EventID,E.Description as Event,E.EventDate as Date
I.Attending as [Att'g],NotAttending as [Not att'g],I.Bootcamp as [Maybe] I.Attended
FROM Invitations I INNER JOIN Events E on I.EventID=E.EventID
WHERE I.MemberID=@ExecID and NotForStats=0
ORDER BY E.EventDate DESC
END
ELSE
BEGIN
select E.EventID,E.Description as Event,E.EventDate as Date
count(*) as Invited,SUM(CONVERT(smallint,I.Attended)) AS Attended
FROM Invitations I INNER JOIN Events E on I.EventID=E.EventID
WHERE I.MemberID IN (select ID FROM Executives WHERE OrganisationID=OrgID
GROUP BY E.EventID,E.Description,E.EventDate
ORDER BY E.EventDate DESC
END


and i'm getting the following syntax errors when i check it -


Msg 102, Level 15, State 1, Procedure sp_GetInvitationsHistoryDetails, Line 10

Incorrect syntax near 'I'.

Msg 102, Level 15, State 1, Procedure sp_GetInvitationsHistoryDetails, Line 19

Incorrect syntax near 'count'.

Msg 156, Level 15, State 1, Procedure sp_GetInvitationsHistoryDetails, Line 23

Incorrect syntax near the keyword 'ORDER'.

Originally i just ran this sql from C# and it worked, obviously added the @ to the variables but it's basically the same.

Any ideas??


View 6 Replies View Related

SQL Server 2012 :: Altering All Objects To Find Syntax Errors

Jul 25, 2014

How to alter all objects in database i want to find if can any syntax errors in my database after restoring from sql 2008 to 2012. I Can create as test and drop them but trying to find a way to alter proc , views and functions..

View 4 Replies View Related

If STATEMENT Within Select Statement Syntax

May 15, 2008

Hi,

I am a newbie to this site and hope someone can help....

I have a select statement which I would like to create an extra column and put an if statement in it.... Current syntax is:

if(TL_flag= '1', "yes") as [Trial Leave]

it is coming up with an error.... I can use Select case but I should not need to as this should work?

Any ideas?

View 2 Replies View Related

Transact SQL :: WMI Alerts Errors

Jul 25, 2008

I am having a problem registering any WMI Event in the ootMicrosoftSqlServerServerEvents namespace on all of my SQL Servers.  It doesn't matter what instance I append behind this either.  MSSQLSERVER fails as will any other named instance.  I get the same exact errors on every server which isn't surprising since they currently all have identical configurations, excluding hardware:
 
"The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax."and it doesn't apply because my servernames are all 8 characters long, and I already applied CU6 to the servers months ago.  The current @@Version on all Servers is:
 
Microsoft SQL Server 2005 - 9.00.3233.00 (X64)   Mar  6 2008 21:58:47   Copyright (c) 1988-2005 Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 5.2 (Build 3790: Service Pack 2)
 
the only differece is that some of them are x86 instead of X64, but the problem occurs on the x86 servers as well.What is interesting is I can register other WMI namespaces just fine, like the following from Jason Massies Blog:
 
EXEC msdb.dbo.sp_add_alert
@name =N'Test',
@enabled =1,
@delay_between_responses =0,
@include_event_description_in =0,
@wmi_namespace =N'.ROOTCIMV2',
@wmi_query =N'SELECT * FROM __InstanceModificationEvent WITHIN 600 WHERE TargetInstance ISA "Win32_LogicalDisk" AND TargetInstance.FreeSpace < 100000'
GO
 
I can create the WMI Alert on my laptop which is build 3054.

View 3 Replies View Related

Transact SQL :: Update Statement In Select Case Statement

May 5, 2015

I am attempting to run update statements within a SELECT CASE statement.

Select case x.field
WHEN 'XXX' THEN
  UPDATE TABLE1
   SET TABLE1.FIELD2 = 1
  ELSE
   UPDATE TABLE2
   SET TABLE2.FIELD1 = 2
END
FROM OuterTable x

I get incorrect syntax near the keyword 'update'.

View 7 Replies View Related

Transact SQL :: Incorrect Syntax Near Order

Sep 18, 2015

select
row_number() over (partition by merrickid order by recorddate asc) as rn,
merrickid,
recorddate,
allocestgasvolmcf,
sum(allocestgasvolmcf) over (partition by merrickid order by recorddate asc) as xxxxxxxx
from dbo.completiondailytb
where merrickid=1965

I get the following message after I insert the sum() over function:

Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'order'.

View 4 Replies View Related

Select Statement In Asp.net Giving Errors

Feb 21, 2006

hi all i built and sql statemnet up in enterprise manager but when i paste it into my asp.net  code it gives error, this is what i have
 
objDA1 = new SqlDataAdapter("select DISTINCT categories.categorydescription, vehicles.vehicleID from vehicles "_&"INNER JOIN ON Vehicles.VehicleID=Parts.VehicleID INNER JOIN Categories ON Parts.CategoryID = Categories.CategoryID "_& "where CategoryID = " & LoadDataByCategory & ";", objConn)
  objDA1.fill(objDS1, "Categories")
 
whats wrong with it ? is it concatinated wrong thanks ?

View 2 Replies View Related

IF Statement Errors In Huge SQL Query

May 23, 2006

I've not gotten the If statement to work.

Before: http://www.webfound.net/sqlbefore.txt

After (with IF statement):
http://www.webfound.net/sqlafter.txt

I don't want to include the deletedpdcs if the month is today in my SUM for PDCs_IL basically is what I'm trying to accomplish here

View 3 Replies View Related

Errors Using Multiple Parameters In A SQL Statement

Feb 23, 2007

In an OLE DB Source in an SSIS package, we are having difficulties using multiple parameters in a SQL statement.

Using a single '?' works fine, but I've read that when you want to map more than 1 parameter you should use 'Parameter0, Parameter1, etc'.

The problem is that when we use Parameter0 and Parameter1 and then try to map it, it says that the query contains no parameters.

Can anyone help with the correct way to use multiple parameters in a SQL query that's part of an OLE DB Source task?

Thanks,

Mike

View 15 Replies View Related

What's The Right Syntax Of This Sql Statement?

Jan 23, 2008

Hi,
I created a sqldatasource (sql server) and a gridview.In the aspx file, i can see the selectcommand:
SelectCommand="select email from mytable"
Now, i want to modify something in the selectcommand produced in the aspx file, in order to get the emails in clickable mode. I knwow i have to add a string like:
<a hef="mailto:mailaddress">mailadress</a>
So i tried this:
SelectCommand="select '<a href="mailto:'+ email +'">' , email + '</a>' from email
But this gives the error: "tag is not well formed".The problem is the " around mailto:
Thanks
Cl.

View 4 Replies View Related

Sql Syntax Statement

May 23, 2008

Here is an sql query but it keeps giving me an error of   (Incorrect syntax near keywork ON)
here is the sql, don't get why this doe not work when I have done it this way multiple times.
select DISTINCT c.strSSN, p.sidstrNAME_IND,
p.sidstrGR_ABBR_CODE, p.sidstrSSN_SM, p.sidstrST_ADDR, p.sidstrADDR_CITY, p.sidstrSTATES_US, p.sidstrZIP_CODE, p.sidstrPAY_GR, p.sidstrMARTL_STAT,
p.sidstrNBR_EXEMPT, p.sidstrST_TAX_CODE, u.lsdbstrPHONE_NBR_HOME, case when sidstrTech_SVC_Code in ('M', 'R', 'S', 'T', 'U', 'Z') then
case when sidstrACT_STAT_PROG in ('5', 'A', 'E', 'F', 'N', 'R', 'S', 'T') then 'AGR' else 'Tech' end else 'M-Day' end
as status from tblAssignedPersonnel as c on ap.strssn = p.sidstrSSN_SM Inner Join
cms.dbo.tblLSDB as u on u.lsdbstrSSN_SM = c.strSSN inner joincms.dbo.tblSidpers as p on ap.strSSN = p.sidstrSSN_SM where intUICID = (select intUICID from tblUIC
where strUIC = '2' and intTaskForceID = '1') order by p.sidstrNAME_IND
 

View 3 Replies View Related

Insert Records Using EXEC Syntax In Transact

Sep 14, 2004

Hi all,

I have to insert records using transact iin the stored procedure. I have some thing like:

DECLARE @Err varchar(100)
DECLARE insertQ varchar(1000)

SET @Err = 'Insertion data'

SET @insertQ =('INSERT INTO dbo.T_ERRORLOG (ERROR_DESCR) VALUES(' + @Err + ')')

EXEC insertQ

But it don't work. Can you help me to solve the problem plz?

Thanks a lot

TT

View 4 Replies View Related

Transact SQL :: Syntax To Group Items In One Line?

Nov 20, 2015

I have records that I get in this format:

ID                       Customer               Type                 TypeNUm
100                      Tiger                    Item                   T100  
100                      Tiger                     Item                   T200
100                      Tiger                     Item                   T300
100                      Tiger                     Shiper                  SAAA 
100                       Tiger                    PO                       POAAA
200                       Panera                  GL                   WE
200                       Panera                  PO                   POBBB

The reftypes are not always the same, what I need is to get it in this form

ID                       Customer               Type              TypeNUm
100                      Tiger                     Item                   T100,T200, T300 
100                      Tiger                     Shiper                  SAAA 
100                       Tiger                    PO                       POAAA
200                       Panera                  GL                      WE
200                       Panera                  PO                     POBBB

View 6 Replies View Related

Transact SQL :: Syntax Check For Archiving A Table

May 12, 2015

I am trying to write a SQL Server query that archives x-days old data from [Archive].[TestToDelete] to [Working].[TestToDelete]table. I want to check that if the records on ArchiveTable do not exist then insert then deleted...which will be converted to a proc later.. archives x-days old data from [Working].[TestToDelete] to [Archive].[TestToDelete] table */Here is the table definition, it is the same for both working and archive tables. There are indexes on: IpAddress, Logdate, Server, User and Sysdate (clustered).

CREATE TABLE [Archive].[TestToDelete]([Server] [varchar](16) NOT NULL,[Logdate] [datetime] NOT NULL,[IpAddress] [varchar](16) NOT NULL,[Login] [varchar](64) NULL,[User] [varchar](64) NULL,[Sysdate] [datetime] NULL,[Request] [text] NULL,[Status] [varchar](64) NULL,[Length] [varchar](128) NULL,[Referer] [varchar](1024) NULL,[Agent] [varchar](1024) NULL) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]/* the syntax, which will be converted to proc is: */SET NOCOUNT ON;DECLARE @Time DATETIME,@R INT,@ErrMessage NVARCHAR(1024)SET @R = 1/* set @Time to one day old data */SET @Time =

[code]....

View 8 Replies View Related

Transact SQL :: Converting Old Outer Join Syntax

Aug 22, 2015

I'm a Power Builder (PB) developer. I've migrated PB from 10 .5 to 12.5, and now I need to migrate the stored procedures from SQL Server 2005 to 2012 as well.I get a invalid expression error when I run the procedures in Power Builder. We have previously been using a lower database compatibility model in 2005, which allowed the procedures to work there. I have learned that =* is the old way to write right outer joins.

                            For example:
                            select  *
                            from    A
                            right outer join
                                    B
                           
[code]...

Is my approach correct, or do I need to add a WHERE condition to it? I don't have access to the production database to check. The development database is in SQL Server 2012 too, sO I will not be able to run the old version there to check.

View 8 Replies View Related

Transact SQL :: GROUP By Field Syntax Error

Oct 8, 2015

I have the following querry:

SELECT APHIST.ReturnDate AS ATDATE
,API_HIST.[ActionPlanItemID]
,API_HIST.[ActionPlanID]
,PIT.[ProductItemID]
,PIT.ProductItemCode
,PIT.Name,

[Code] ....

That query is suppose to add to calculation field OutStock and InStock based on the value of n

When executing this  query I get the following message :

Column 'Sales.ActionPlan_History.ReturnDate' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

View 3 Replies View Related

Syntax For IF-THEN In SQL Select Statement

Sep 3, 2007

I need to use IF-THEN in a SQL Select statement.  Using Google
I have found a couple of obscure references to this but nothing that I
can use.  Tried various combinations without luck.  Can
anyone point me to a good resource or supply a simple example of proper
syntax?  Thanks in advance for any help provided.

View 2 Replies View Related

Incorrect Syntax Near ','. Sql Statement

Dec 4, 2007

 SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString2"].ToString());        SqlCommand myCommand = new SqlCommand("SELECT (Deadline, Description, Headline, AddressField, OrganizationField, NameField, FileField, EmailField, CommentField) FROM RegistrationFormDB_Info WHERE (UserName = @UserName AND TournamentName = @TournamentName)", myConnection);        SqlParameter myParam = new SqlParameter();        myParam.ParameterName = "@UserName";        myParam.Value = User.Identity.Name;        myCommand.Parameters.Add(myParam);        myParam = new SqlParameter();        myParam.ParameterName = "@TournamentName";        myParam.Value = Request.QueryString["TournamentName"];        myCommand.Parameters.Add(myParam);        myConnection.Open();        SqlDataReader myReader = myCommand.ExecuteReader();   <======================  I continue to get this error and I can't figure out the problem!  Anything helps.  Thank you very much. 

View 1 Replies View Related

SQL Syntax With For Select Like Statement

Dec 6, 2007

Hello,
 
I have the following statement that I am trying to convert to a "like" statement in a SqlDataSource for a web application.  I can't seem to get the syntax correct.  Would someone be able to assist with this?  Thanks!
SELECT * FROM [Employees] WHERE ([LName] = @LName) ORDER BY [LName], [FName]
Something like below.
SELECT * FROM [Employees] WHERE ([LName] LIKE '@LName%') ORDER BY [LName], [FName]

View 3 Replies View Related

SQL Statement Syntax Error?

Apr 22, 2008

SELECT DISTINCT CONVERT (nvarchar , tblSubject.Subject, 108) AS SubjectTime, CONVERT (nvarchar(11), tblSubject.Subject, 100) AS Date FROM tblLooker,tblSubject,tblStop WHERE NOT (SELECT DISTINCT CONVERT (nvarchar , tblSubject.Subject, 108) AS SubjectTime, CONVERT (nvarchar(11), tblSubject.Subject, 100) AS Date FROM tblSubject, tblLooker, tblStop WHERE tblSubject.Subject > tblLooker.Looker AND tblSubject.Subject < tblStop.Stop AND tblLooker.id = tblStop.id) Msg 170, Level 15, State 1, Line 5Line 5: Incorrect syntax near ')'. Can anyone tell me why this is not working? Thanks   

View 1 Replies View Related

LIKE Syntax In A SELECT Statement

May 19, 2008

What is the syntax for making a query using like, the below is my code
 <asp:SqlDataSource ID="Search" runat="server"
ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>"
ProviderName="<%$ ConnectionStrings:DatabaseConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM [Products]WHERE category LIKE %@category%">
 
<SelectParameters>
<asp:QueryStringParameter Name="category"
QueryStringField="category" Type="string" />
</SelectParameters>
</asp:SqlDataSource>
 Its giving a syntax error but I dont know how to change it.
Please advise, thanks!

View 5 Replies View Related

EFFECTIVE SQL STATEMENT SYNTAX

Oct 3, 2001

Hi all,

I am a java developer having little bit knowledge in sql statements.
can any body guide me what is the effective way of using sql statement
to achieve the following goal.

here is the requirement.

1. There are 2 tables A & B.

2.The table 'B' may or maynot have an equivalent entry for the primary
key of table a.

3. select column1 (of A), column 2(of B) from table a and b.

4. now column2 should give a value, if there is a corresponding
entry in table b.other wise null.

5. at any time there may be 0 to 1 record in table b for the primary
of table a.


thanks in advance
krishna

View 1 Replies View Related

CASE Statement Syntax

Jun 21, 2000

Can someone tell me what is wrong with my syntax? I am getting several errors:

Incorrect syntax near keyword 'CASE'
Incorrect syntax near keyword 'WHEN'


Incorrect syntax near '@Tablename'


CREATE PROCEDURE al_readcampsignup


@User_ID int,


@Pagenumber smallint,


@Tablename varchar(10)


AS


CASE @Mypagenumber WHEN 1 THEN SELECT Blah FROM tempcampsignup WHERE Camp_ID = @User_ID WHEN 2 THEN SELECT Blah FROM @Tablename WHERE Camp_ID = @User_ID WHEN 3 THEN SELECT Blah FROM @Tablename WHERE Camp_ID = @User_ID END

Thanks

View 1 Replies View Related

Syntax To Join With And Statement

Jan 17, 2014

I inherited a query and I am getting an error of Unsupported literal in join in the INNER JOIN FRDM.dbo.MEMBER_SUBSC FRDM_dbo_MEMBER_SUBSC2

ON (frdm.dbo.CLAIM_HEADER_WITH_VOIDS_VIEW.SBSB_CK = FRDM_dbo_MEMBER_SUBSC2.SBSB_CK AND FRDM_dbo_MEMBER_SUBSC2.MEME_SFX
= '00')statement. Specifically the AND FRDM_dbo_MEMBER_SUBSC2.MEME_SFX
= '00')part.
SELECT frdm.dbo.CLAIM_HEADER_WITH_VOIDS_VIEW.GRGR_ID AS 'group number'

[code]....

View 1 Replies View Related

SYNTAX Help, Correct Way To Use LIKE In Statement

Feb 27, 2007

Hi, I'm new to SQL and was wondering if there was an easier way to filter data.

I have two tables -

The first table called Names of Companies has a column named: NAMES

NAMES
XYZ Company
ABC Limited Liability Company
ZZZ Corporation
KKK Inc.
ABC Inc.

The second table called Keywords has a column named: WORDS

WORDS
Company
Limited


I want to search for all NAMES that contain the WORDS in some form

The results should be:

NAMES
XYZ Company
ABC Limited Liability Company

Technically, I can get the results I want by manually typing into the SQL statement all the words that appear in the WORDS column.

SELECT *
FROM [Names of Companies]
WHERE [Names of Companies].Names Like "*Company*" Or ([Names of Companies].Names) Like "*limited*"));

But is there a way that I reference the table Keyword instead of typing into the query statement all the words that appear in the column WORD? I have a lot of words to search for.

Can anyone recommend a better way to do this?

Thanks for all your help!

View 8 Replies View Related

Incorrect Syntax Using IF Statement

Apr 6, 2006

Hi,I'm new to SQL Server Programming, I work with ASP a lot, but latelyI've been trying to create Stored Procedures, etc. I'm having aproblem writing a simple IF statement.. I don't seem to understand whyit's giving me this error. I've search around on Google Groups, but Istill don't get it.=================USE msdbIF NOT EXISTS (SELECT * FROM sysjobs WHERE name = 'Scheduled Nightfax')END=================My error is:Server: Msg 156, Level 15, State 1, Line 5Incorrect syntax near the keyword 'END'.Thanks for any help.

View 2 Replies View Related

If Statement ... Syntax Error

Apr 9, 2008

hi, i've got this code





Code Snippet

go

create proc dbo.sp_GetFilterOrgIDs(@ID int)

as

select distinct


O.ID

from


Organisations O

if (@ID != 0)

begin


where O.ID = @ID
end






and am getting


Incorrect syntax near the keyword 'where'.

any idea why??

View 6 Replies View Related

IIF Statement Has Syntax Error...please Help...

May 20, 2008

I am trying to figure out the syntax for the following:

=iif(fields!ExtTripCount.value = 1,sum(Fields!ExtTripCount.value),0) / (count(fields!SvcCallNumber.value))* 100

I am trying to take all the trips that equal a one and divide them by the total number of service calls and then multiple them by 100 to get the percentage.

I am receiving the following errror: "The value expression refers to the field 'SvcCallNumber'. Report item expressions can only refer to fields within the current dta set scope or, if inside an aggregate, the specified data set scope...

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved