Sql Syntax For Multiple Likes Phrases In Where Clause

Nov 16, 2007



You know how you can go:



Code Block
where control_id in (11111,22222,33333,44444)




or




Code Block
where TextName in ('11111','22222','33333','44444')




and you can do this:




Code Block
where TextName like '11%' or TextName like '22%'





well how do you do this? Or can you... or can we right a function to do it... or are we just hosed writing like after like.

where TextName like in ('11%','22%',... and so on)? is anything like that possible?

or better yet
where TextName like in ( select substring(columnName, 1, 2) + '%' from whatever )

can you imagine the dynamics if that syntax actually worked?

Can a function be written to mimic this functionality? so I can do something like this:
where TextName = function('11%,22%,33%')

View 13 Replies


ADVERTISEMENT

Replace Multiple LIKEs

Sep 30, 2006

I have a query below that performs horribly:@KeywordOne char(6),@KeywordTwo char(6),@KeywordThree char(6),@KeywordFour char(6),@KeywordFive char(6)SELECTc.SomethingFROMdbo.tblStuff cWHEREc.SomeColumnName = 0AND (c.Keyword LIKE '%' + @KeywordOne + '%' OR @KeywordOne is Null)AND (c.Keyword LIKE '%' + @KeywordTwo + '%' OR @KeywordTwo is Null)AND (c.Keyword LIKE '%' + @KeywordThree + '%' OR @KeywordThree isNull)AND (c.Keyword LIKE '%' + @KeywordFour + '%' OR @KeywordFour = isNull)AND (c.Keyword LIKE '%' + @KeywordFive + '%' OR @KeywordFive = isNull)The contents of column c.Keyword looks like this:Row1: 123456,321654,987987,345987Row2:Row3: 123456,987987etc.What can I do to get this to perform reasonably? I cannot use full-textsearch.Any help is appreciated.lq

View 4 Replies View Related

Incorrect Syntax Near WHERE Clause

May 14, 2007

 <asp:SqlDataSource ID="productsUpdate" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringAccountType %>"
SelectCommand="SELECT [ProductID], [ProductName], [ImageTitle], [ImageData], [ImageMimeType] FROM [Products] WHERE [ProductID] = @ProductID"
UpdateCommand="UPDATE [Products] SET [ImageTitle] = Null, [ImageData] = Null, [ImageMimeType] = Null WHERE [ProductID] = @ProductID" InsertCommand="INSERT INTO [Products] ([ImageTitle], [ImageData], [ImageMimeType]) VALUES (@ImageTitle, @ImageData, @MimeType) WHERE ([ProductID] = @ProductID)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="ProductID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ImageTitle" />
<asp:Parameter Name="ImageData" Type="string" />
<asp:Parameter Name="MimeType" Type="string" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ImageTitle" Type="String" />
<asp:Parameter Name="ImageData" />
<asp:Parameter Name="MimeType" Type="String" />
</InsertParameters>
</asp:SqlDataSource> Hi Guys, new to development using visual studio and vb.net 2.0. and SQL express. Have a small problem.I have an update command which im using to change the values of a blob image table to NULL so that i can then insert a new image into the table. This works fine. My problem is that my insert statement has an error and i cant figure this out. if i dont add the where clause it works fine but inserts the new image into the table without the product data, i want to insert the new image into the existing product information.   The error message i keep getting is "incorrect syntax near where"Any help would be greatly appreciatedThanks

View 7 Replies View Related

Syntax Error On Where Clause

Feb 6, 2005

I have the code below and the where clause is giving me errors, I have already setup FT Index, I think the error is lack of ' or " or "" or some kinda syntax pls help... as I can figure it out

I passed the word MBAISE



where CONTAINS(*, '+@searchstring+' )


Declare @myStatement varchar(8000)
Declare @LastRec int
Declare @FirstRec int
SELECT @FirstRec = (@CurrentPage - 1) * @PageSize
SELECT @LastRec =(@CurrentPage * @PageSize + 1 )

SELECT @myStatement = ' SELECT SalaryStatistical, EmployerID,JobLocation, location, SectorID
FROM #TEMP

where CONTAINS(*, '+@searchstring+' )

AND (LastLogin >= dateadd(d, -' + @HowManyDays + ', getdate())
AND (ID > '+ convert(varchar(20),@FirstRec) +')
AND (ID < '+convert(varchar(20),@LastRec) +')
AND (SalaryStatistical > '+ convert(varchar(20),@SalaryStatistical)+')

'
IF @JobLocation != @myzero

BEGIN
SELECT @myStatement = @myStatement + ' AND (JobLocation IN ('+convert(varchar(90),@JobLocation)+')) '
END

IF @sectorID != @myzero
BEGIN
SELECT @myStatement = @myStatement + ' AND (SectorID IN ('+convert(varchar(90),@sectorID)+')) '
END

SELECT @myStatement = @myStatement
print @myStatement

exec(@myStatement)


GO

View 1 Replies View Related

Syntax Help With Orderid % 2 = 1 In WHERE Clause

Nov 6, 2007

I started reading a very informative book (Inside Microsoft SQL Server 2005: T-SQL Querying) that uses the following example.SELECT orderid, customerid,
COUNT(*) OVER(PARTITION BY customerid) AS num_orders
FROM dbo.Orders
WHERE customerid IS NOT NULL
AND orderid % 2 = 1;
Being new to T-SQL, I don't understand what is going on in the last line "orderid % 2 = 1". I tried searching "Books On Line" with no answer. Is there a good reference or textbook out there I can use to find the answers to specific syntax questions?

View 3 Replies View Related

Syntax Error In FROM Clause - Help Needed Please!!

Jun 8, 2008

 Hi all,I am a newbie to asp and have been using VWD to make a database for an assignment but I am having big problems trying to extract some data to a datalist view. I intend to use this page to display all information of hotel rooms. I know its probably really obvious to some of you but its driving me mad!!! Any help would be greatly appreciated.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)        Dim ds As New DataSet()        Dim sGetRooms As String = "SELECT RoomID, RoomType, " _          & "RoomName FROM Rooms2 " _          & "WHERE RoomType LIKE @RoomType " _          & "ORDER BY RoomType"        Dim sGetroomsizeandprice As String = "SELECT ID, RoomSize, RoomPrice, @RoomType " _          & "FROM roomprices JOIN Rooms2 ON Rooms2.ID = roomprices.ID " _          & "WHERE RoomType LIKE @RoomType " _          & "ORDER BY RoomPrice"        Dim sConnect As String = ConfigurationManager.ConnectionStrings("White Sand's Hotel - Dan MahilConnectionString").ConnectionString        Using con As New OleDbConnection(sConnect)            Dim da As New OleDbDataAdapter(sGetRooms, con)            Dim param As New OleDbParameter("RoomType", OleDbType.VarChar, 10)            param.Value = Request.QueryString("RoomType") & "%"            da.SelectCommand.Parameters.Add(param)            Try                da.Fill(ds, "Rooms2")                da.SelectCommand.CommandText = sGetroomsizeandprice                da.Fill(ds, "roomprices")            Catch ex As Exception                Label4.Text = "ERROR: " & ex.Message                Exit Sub            End Try        End Using        Dim pkcol As DataColumn = ds.Tables("Room2").Columns("RoomID")        Dim fkcol As DataColumn = ds.Tables("roomprices").Columns("ID")        Dim dr As New DataRelation("MenuLink", pkcol, fkcol)        ds.Relations.Add(dr)        DataList1.DataSource = ds        DataList1.DataMember = "Rooms2"        DataList1.DataBind()    End Sub  

View 2 Replies View Related

ANSI-92 Inner Join Vs. Where Clause Syntax

Jan 11, 2005

Having problems rewriting my join condition using the "inner join" syntax.

My query, working with an intersection table:

SELECT Description, EmailAddress
FROM Accounts_Roles r, Accounts_Users u, Accounts_UserRoles ur
WHERE
r.RoleID = ur.RoleID
AND
u.UserID = ur.UserID

This works fine, but i want to write it using 'inner join' style, so I tried:

SELECT Description, EmailAddress
FROM Accounts_Roles r, Accounts_Users u
INNER JOIN Accounts_UserRoles ur
ON
r.RoleID = ur.RoleID
AND
u.UserID = ur.UserID

which gives me an error (The column prefix 'r' does not match with a table name or alias name used in the query.)

Any ideas as to how I'm screwing this up would be appreciated.

Thanks,
Gordon Z

View 3 Replies View Related

Syntax For WHERE Clause For Access Database

Oct 17, 2006

I have used this query statement with a SQL Server 2005 database and need to use something similar with an Access database:

SELECT products.*, Category AS Expr1
FROM products
WHERE (Category = @Category)

When I test this in a table adapter there is no preview due to lack of parameter. I seem to recall that Access uses different syntax in the WHERE filter clause (i.e., not @). Can someone help me out with this?

View 3 Replies View Related

'Include Clause' In Create Index Syntax

Mar 26, 2008

What is the equivalent for INCLUDE clause (in Create index syntax) in SQL Server 2000.
SQL Server 2005 will support Include clause in Create index syntax . How to attain it in SQL Server 2000

Example : I have below query executable in SQL Server 2005

CREATE INDEX Index_Name ON mytable(col1 ASC) INCLUDE (name,id);

What is the equivalent for the above query in SQL server 2000

Thanks ,
Sushma

View 1 Replies View Related

FTS Q - Proximate Meaning Of Phrases

Sep 20, 2005

Hi

Is it possible to find records that contain the string "cyber-shot" when the value for search is "cybershot"?? (This is an example and I need a dynamic solution)

Thanks,

Inon.

View 2 Replies View Related

Syntax Error When Building Up A Where Clause In Stored Procedure

Aug 9, 2006

Can anyone tell me why the line highlighted in blue produces the following error when I try to run this stored proc? I know the parameters are set properly as I can see them when debugging the SP.
I'm using this type of approach as my application is using the objectdatasource with paging. I have a similar SP that doesn't have the CategoryId and PersonTypeId parameters and that works fine so it is the addition of these new params that has messed up the building of the WHERE clause
The Error is: "Syntax error converting the varchar value '  WHERE CategoryId = ' to a column of data type int."
Thanks
Neil
CREATE PROCEDURE dbo.GetPersonsByCategoryAndTypeByName (@CategoryId int, @PersonTypeId int, @FirstName varchar(50)=NULL, @FamilyName varchar(50)=NULL, @StartRow int, @PageSize int)
AS
Declare @WhereClause varchar(2000)Declare @OrderByClause varchar(255)Declare @SelectClause varchar(2000)
CREATE TABLE #tblPersons ( ID int IDENTITY PRIMARY KEY , PersonId int , TitleId int NULL , FirstName varchar (50)  NULL , FamilyName varchar (50)  NOT NULL , FullName varchar (120)  NOT NULL , AltFamilyName varchar (50)  NULL , Sex varchar (6)  NULL , DateOfBirth datetime NULL , Age int NULL , DateOfDeath datetime NULL , CauseOfDeathId int NULL , Height int NULL , Weight int NULL , ABO varchar (3)  NULL , RhD varchar (8)  NULL , Comments varchar (2000)  NULL , LocalIdNo varchar (20)  NULL , NHSNo varchar (10) NULL , CHINo varchar (10)  NULL , HospitalId int NULL , HospitalNo varchar (20)  NULL , AltHospitalId int NULL , AltHospitalNo varchar (20)  NULL , EthnicGroupId int NULL , CitizenshipId int NULL , NHSEntitlement bit NULL , HomePhoneNo varchar (12)  NULL , WorkPhoneNo varchar (12)  NULL , MobilePhoneNo varchar (12)  NULL , CreatedBy varchar(40) NULL , DateCreated smalldatetime NULL , UpdatedBy varchar(40) NULL , DateLastUpdated smalldatetime NULL, UpdateId int )
SELECT @OrderByClause = ' ORDER BY FamilyName, FirstName'
SELECT @WhereClause = '  WHERE CategoryId = ' +  @CategoryId + ' AND PersonTypeId = ' + @PersonTypeIdIf NOT @Firstname IS NULLBEGIN SELECT @WhereClause = @WhereClause + ' AND FirstName LIKE ISNULL(''%'+ @FirstName + '%'','''')'ENDIf NOT @FamilyName IS NULLBEGIN SELECT @WhereClause = @WhereClause + ' AND (FamilyName LIKE ISNULL(''%'+ @FamilyName + '%'','''') OR AltFamilyName LIKE ISNULL(''%'+ @FamilyName + '%'',''''))'END
Select @SelectClause = 'INSERT INTO #tblPersons( PersonId, TitleId, FirstName, FamilyName , FullName, AltFamilyName, Sex, DateOfBirth, Age, DateOfDeath, CauseOfDeathId, Height, Weight, ABO, RhD, Comments, LocalIdNo, NHSNo, CHINo, HospitalId, HospitalNo, AltHospitalId, AltHospitalNo, EthnicGroupId, CitizenshipId, NHSEntitlement, HomePhoneNo, WorkPhoneNo, MobilePhoneNo, CreatedBy, DateCreated, UpdatedBy, DateLastUpdated, UpdateId)
SELECT  PersonId, TitleId, FirstName, FamilyName , FullName, AltFamilyName, Sex, DateOfBirth, Age, DateOfDeath, CauseOfDeathId, Height, Weight, ABO, RhD, Comments, LocalIdNo, NHSNo, CHINo, HospitalId, HospitalNo, AltHospitalId, AltHospitalNo, EthnicGroupId, CitizenshipId, NHSEntitlement, HomePhoneNo, WorkPhoneNo, MobilePhoneNo, CreatedBy, DateCreated, UpdatedBy, DateLastUpdated, UpdateId
 FROM vw_GetPersonsByCategoryAndType '
EXEC (@SelectClause + @WhereClause +@OrderByClause)

View 1 Replies View Related

Transact SQL :: Finding Syntax To Combine IN And CASE In A WHERE Clause?

Oct 29, 2015

I cannot seem to find the syntax to combine IN + CASE in a WHERE clause

WHERE
ses.BK_MS_SESSION <= '2015-03'
AND vis.CAT_DRAW_STATUS =
(CASE ses.BK_MS_SESSION
WHEN '2015-03' THEN vis.CAT_DRAW_STATUS
ELSE
CASE stat.BK_MS_VISIT_STATUS
WHEN 'T' THEN 'X'
ELSE vis.CAT_DRAW_STATUS
END
END
) IN ('D','R')

View 7 Replies View Related

What Is The Best And Most Effective Way To Find The Most Related Phrases?

Dec 10, 2007

Hi, I am looking for a sql statemnt that find the most related phrases, how to do that? For example, I want to find the related phrases bellow for the following phrase: "How to install the software"
1- "Installation does not work"
2- "installation"
3- "steps to install the software"
 
It's obvoius that phrase number 2 and 3 are related to that phrase, how to do that using sql?
 
Regards.

View 1 Replies View Related

Full Text Search - Phrases Help

Jan 31, 2008

Hello, I hope you can help!Database: SQL Server 2005Code: ASP.net 2.0 / C#I have implemented full text search that works fine with single word searches but I receive a syntax error when the search string contains a space. The way the code works is a user selects a "Category" in ListBox3 and search results (company names) are displayed in ListBox4.   
Here is an error example:Search on "Absorbers, Nuclear Radiation"Error:Syntax error near ',' in the full-text search condition 'Absorbers, Nuclear Radiation'. My Code for Selecting (ListBox4):
<asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:XYZ%>"
SelectCommand="SELECT [Categories], [SupplierName] FROM [Suppliers] WHERE CONTAINS([Categories], @Category)" ProviderName="System.Data.SqlClient">
<SelectParameters>
<asp:ControlParameter ControlID="ListBox3" Name="Category" PropertyName="SelectedValue"
Type="String"/></SelectParameters>
</asp:SqlDataSource>
<asp:ListBox ID="ListBox4" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource6"DataTextField="SupplierName" DataValueField="SupplierName" Style="z-index: 103;
left: 26px; position: absolute; top: 302px" Width="90%" Height="200px"></asp:ListBox>
 
Here is where I assign the value to the parameter @Category (ListBox3):
 
<asp:ListBox ID="ListBox3" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource5"
DataTextField="Category" DataValueField="Category" ></asp:ListBox>
&nbsp;<asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:XYZ%>"
SelectCommand="SELECT [Category] FROM [Categories] ORDER BY [Category]">
</asp:SqlDataSource>
 
Typical data format in the Categories database field. Note: Each entry in the field is separated by a semicolon.Abrasives;Absorbers, Nuclear Radiation;Accelerators & Accessories;Adhesives;
I read somewhere you could possibly add quotations to the search string and it could possibly work but I do not know how to do that??Thanks for your help!
 

View 2 Replies View Related

Calculation Of A Degree Of Similarity Of Phrases

May 19, 2004

Hi!
i make The Extended stored procedure for MS SQL Server which
Calculation of a degree of similarity of phrases.

Purpose:
One of the most complex and important problems for the developer and the operator of a database is maintenance of uniqueness names in the most important references of system.
Offered function can be used in SQL inquiry as criterion of sorting of the directory according to similarity with a required phrase.

Features:
· incredibly high speed of data processing
· Unique algorithm analyzing similarity of phrases even at significant divergences in required phrases
· is not required installation of additional libraries to each client - library DLL must benn installed only on a server.
· Result is all the table sorted in decreasing order phonetic similarity (probably use of operator TOP for sample only the limited quantity of the most similar variants)
· Use of user server function supposes use in Stored procedures, Views and any SQL expressions
· Spends a minimum of server memory

--------------------------------------------------------------------------
If the decision of the given problem is interesting to you and there is an opportunity desire and an opportunity to test http://kozin1.narod.ru (http://kozin1.narod.ru/newsite/index.html?english.htm)
Dll and sample scripts in rar archive (2,5 KB)
I thank in advance

View 2 Replies View Related

Sql Query Uisng Likes

Nov 8, 2004

I have this query that is searching using the hotel name as its first parameter and the hotels location (e.g. london) ast is second parameter.

My client wants to search on part of the hotel name and part of the location name (so I used the like statement)

Oh and the location searches using like on 3 location fields.

My client is complaining when he types hilton and leeds he gets all the hilton hotel in Leeds plus a few extra hotels that aint hilton hotels. I think the query is to senesitive for its own good but he's pushing me on this issue so could anyone advise me if this query could be made to only select the hotels with a name like hilton in leeds. I've pasted this query below. Thanks for your time.

By the way one hotel it pulls up which is wrong is Heath Cottage hotel whos location field is leeds.

SELECT *
FROM hotel
WHERE name LIKE + '%' @Hotelname + '%' AND
location1 LIKE '%' + @city + '%' OR
location2 LIKE '%' + @city + '%' OR
location3 LIKE '%' + @city + '%'

View 2 Replies View Related

Simple Sql Select With 2 Likes

May 20, 2005

Hi all might seem simple but im having trouble.
how do i include 2 likes in a select:

SELECT from TABLE WHERE name like 'SIB' or 'MIWS' ORDERBY name;

is this valid

Craig

View 1 Replies View Related

Challenging Likes Wildcard

Jul 19, 2006

Hi all,

I need to search the field containing the word I enter, but this word is bracketed by "{{" and "}}". For example, I would like to search the keyword apple, I need to search by the following sql statement.

select name from table where name likes '%{{apple}}%'

But the case is that that column may contain some space between the bracket and the keyword. i.e. {{     apple  }}. How can I write a sql statement to search name from the keyword?

Thanks

Spencer

View 6 Replies View Related

CTE Error: Incorrect Syntax Near The Keyword 'with'. If This Statement Is A Common Table Expression Or An Xmlnamespaces Clause,

Aug 3, 2006

I am having this error when using execute query for CTE

Help will be appriciated

View 9 Replies View Related

Configuration File Locations - Likes To Say It Can't Load Them In Designer

Feb 28, 2006

I have a package and added a configuration file to it to hold settings such as connection strings etc.

When I open the package up in the designer and check where the configuration file is from, it likes to specify it with a full path like this:

\myserverprojectspackageslah.xml

Where blah.xml is the configuration file and the package file is in the same exact directory.

This creates an issue when I use build and then try to install the package on a server. When installing, the server tries to read the config from \myserverprojectspackageslah.xml which it can not.

Conversely I've tried editing the location in the designer changing it to just be "blah.xml". Then after using the build option I am able to install the package successfully on the server (it can not find the xml file).

However when I then load the package later in the designer to try to edit or chagne it, the designer complains that the "configuration file could not be loaded" and it can't find it even though it is in the same directory that the package definition file is in.

What's going on with this and how do i solve it?

View 1 Replies View Related

Multiple Where Clause?

Jun 11, 2007

where exigo_data_sync.orderdetail.itemcode in (B1001, B1001B, B1007, B1007B, B1008, B1008B, B1000, B1000B, B1006, B1006B, B1009, B1009B)

I keep getting a ADO error stating invalid column names...these are not column names they are the data that i want to use in the where clause. What am I doing wrong?

View 2 Replies View Related

Sql WHERE Clause With Multiple Parameters

Jun 28, 2006

hello. I have a database that a client developed that I need to pull data from. it consists of articles that fall into a range of 3 main categories. each article will have up to 7 different subcategories they fall into. I need to be able to sort by main category as well as by subcategory. But when I create the SQL query it gets really messy. I tried using WHERE  Cat1= comm OR leg OR and so on, but there are seven categories so this gets very cumbersome and doesn't quite work. Is there a way to create an array or a subquery for this? I am a total newbie, so any help is much appreciated!

View 2 Replies View Related

Multiple Join Clause

Feb 12, 2004

I have a table "Users" like this:

GroupId
CompanyId
UserId

I need to query the users getting the company's and group's names, but I only know how to join one table. Example:

Select UserId, GroupId, Groups.Name, CompanyId, Companies.Name
From Users JOIN Groups ON Users.GroupId = Groups.Id

Hon can I add the companies table in the Join ?

Thanks,
Moshe

View 2 Replies View Related

Multiple Criteria In WHERE Clause (was T-SQL)

Oct 5, 2005

How can you handle multiple criteria query in T-SQL ? i wrote selection query and in my where clause i have about 7 different criteria and for some reason when i run the query i do not get any error but i do not get any data return.

So is there any other way to handle multiple criteria in T-SQL ?

View 12 Replies View Related

Where Clause With Multiple Cases

Nov 28, 2012

I have a table with a field that contains an integer which represents the state of a record. This field "intType" may contain values 0-4.

A parameter in my stored procedure "@intUserType" may contain values 0-3

If @intUserType = 0, I need to select the records where intType = 0 or 3 but if @intUserType = 3, I need to return all records where intType > 1, all other values of @intUserType should return no records

The query I am working with seems a bit forced and I feel like it could be simplified, but I can't seem to wrap my head around it.

This is what I am working with:

Code:
SELECT * FROM tblEmployees
WHERE (intType = (CASE WHEN @intUserType = 0 THEN 0 ELSE NULL END)
OR intType = (CASE WHEN @intUserType = 0 THEN 3 ELSE NULL END)
OR intType > (CASE WHEN @intUserType = 3 THEN 1 ELSE NULL END))

Maybe it is as good as it needs to be ... I don't know .. I've only been using SQL regulary for a couple of months and I have not had the time to really study it in depth.

View 4 Replies View Related

WHERE Clause With Multiple ANDs

Apr 2, 2015

I have a table (tblAttributes) that looks like this:

ID|ReferenceNumber|AttrID|AttrVal
1|1|90|7
1|1|91|8
1|1|92|9
2|1|90|10
2|1|91|11
2|1|92|12

I need to return all the distinct IDs where the combination of AttrID and AttrVal matches multiple criteria for that specific ID.

I have the following:

SELECT DISTINCT(ID)
FROM
((SELECT a.ID
FROM tblAttributes AS a
WHERE a.AttrID = 90 AND a.AttrVal = 7) AS x
INNER JOIN
(SELECT a.ID
FROM tblAttributes AS a
WHERE a.AttrID = 91 AND a.AttrVal = 8) AS y
ON x.ID = y.ID)

View 5 Replies View Related

Using Multiple Values In IN CLAUSE

Jul 26, 2006

how can i use multiple values in IN CLAUSE in a SQL query, that too when the number of values are changing at runtime.

complete SQL code required...............

I have following picture in mind but the values(in IN clause) are changing at Runtime

DECLARE @groups TABLE (group_id int)

SELECT * FROM abc WHERE abc_id IN (SELECT group_id FROM @groups)

View 4 Replies View Related

Multiple Where Clause On One Report

Aug 14, 2007



Hello People, Please help. I have a basic report with a parameter in the 'Where" clause called (@Stat) from the statement below:
" WHERE contractinfo.termdate >= GETDATE()
AND provider.status= 'Active' AND provider.credentialstatus = (@Stat)"

This variable has one of two values: 'A' or 'B' that the user selects, how do I set it up so that if user selects say 'A' then the Where clause would go to one set of constraints ie
"WHERE contract.description NOT LIKE 'NON%' "

But if the user selects 'B' then the Where clause would go to a different set of constraint ie
"WHERE contract.description LIKE 'NON%' "
Thanks


View 4 Replies View Related

ORDER BY Clause With Multiple Tables

Aug 25, 2005

Hi AllI am having a problem with an ORDER BY clause when selecting information from multiple tables. EgSELECT i.InvoiceId, pd.PayDescription, u.UserNameFROM   Invoice i LEFT OUTER JOIN tblPay ON i.PayId = pd.PayId                       LEFT OUTER JOIN tblUsers ON i.UserId = u.UserIdORDER BY pd.PayDescriptionthis is just an example my query is a lot more complex. Is there any simply way you can do an order by in this way?I am writing this for MSSQL Server 2000ThanksBraiden

View 6 Replies View Related

Like Clause - Preventing Multiple Cases

Sep 9, 2013

I have a like clause like this:

WHERE COLUMN LIKE CAT1%
or
COLUMN LIKE CAT2%
or
COLUMN LIKE CAT3%
ETC..

I want to know if it is possible just have one like clause from 1-9:

CAT1, CAT3, ...., CAT9

View 3 Replies View Related

Stuck With WHERE Clause With Multiple Elements

Jul 20, 2005

HiI'm a bit stuck with a SELECT query. This is a simplified version ofwhat I need. I've had a look in a few books and online but I'mdefinitely missing something. I'm trying to avoid looping and cursors.I'll be running this in a stored procedure on SQL 7.I have a separate query which returns a series of numbers, A, say 101103 107 109 113.I have a table (tableB) with a field myFieldB where I have anotherseries of numbers, B. I want return each row in tableB wherei - ALL values in A existii- ANY values in A existFor ii, I can use WHERE myFieldB IN AHow about for i?Is there a good guide on the web or a book on WHERE clauses and/ormore complex SQL?Thanks in advance!Sam

View 1 Replies View Related

To Use Multiple Value Paramater In The IN List Of A Where Clause

Jan 8, 2008

I have a parent and child package. i pass a parent package variable called @abc with a value of (1,2,3,4,5,6) to the child package. here in the oledb source i have a select statement like,
select *
from A
where id in (@abc)

It gives me an error. any way to make this work.

View 14 Replies View Related

Multiple Conditions In An UPDATE Clause

Dec 12, 2007

I have a table (GLTRANS) with thousands of lines.
1 column in the table (ACCNO) has 300 different values which all need to change to a new value.

ie. 11100 all change to 8100
11200 all change to 8200

I know how to do a simple UPDATE
UPDATE GLTRANS
SET ACCNO = '8100'
WHERE ACCNO = '11100'

But how can i combine into 1 script rather than having to continually change this script 300 times??


Thanks
Wilbur

View 6 Replies View Related







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