.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Combining LIKE and IN statements

Posted By:      Posted Date: September 26, 2010    Points: 0   Category :Sql Server

I want to combine Like and IN statement:

I need some thing like follwoing query for n number of values:

Select * from Table1 where Column1 Like ('ABC%', 'XZY%', ...n number of values)

As it is n number of values so I cannot use 'OR' or 'AND' statements.

Please let me know any solution for this.

Thanks in advance!!

View Complete Post

More Related Resource Links

ListView DataPager with SQL-Statements that already return only paged data.



As far as I understand the ListView-Control and the DataPager-Control, they work like this: The ListView gets its datarows from its data source, then the DataPager causes the ListView to display only a subset of those rows.

So what, when I want to use custom databinding for the ListView, that *already* gets the certain subset from SQL-Server (for better performance). Can I and how can I use the DataPager then?

Thanx, S.

Combining two LDAP queries


Hey guys, I have these two queries I'd like to combine into one.  Is there any way of doing it?
Query 1: (&(!cn=SystemMailbox{*})(&(&(ou>="")(name=executive*)(objectCategory=organizationalUnit)(ou=*operations))))
Query 2: (&(!cn=SystemMailbox{*})(&(ou>="")(name=50*)))
Thanks in advance.

Hey guys, I have these two queries I'd like to combine into one.  Is there any way of doing it?


Multiple update statements per row in Gridview Edit


I want to set up a gridview that will display data like this

WeekEndingDate Project Category Sun Mon Tues Wed Thu Fri Sat
8/14/2010      proj1   test     2   1   2    3   2   1   0
8/21/2010      proj1   test     0   2   2    2   2   1   0
8/28/2010      proj1   test     0   1  

Delete spaces created by combining 2 fields


Howdy, this is kind of a continuation of an answer I got from this thread:  http://forums.asp.net/t/1592766.aspx

My users will enter a city/station where an incident occured, and the date.  The trigger below does work, but it will occasionally put spaces between the citystation and the date.  I think this happens when the citystaion name is not very long, but not sure.

(ex: city____08242010)

How can I make sure that if the incidentid is going to have spaces, that sql deletes those spaces?  I need the id to be space free.





TRIGGER [dbo].[tr_AddID1] ON [dbo].[tblIncidents] INSTEAD

Combining data from 2 lists, then summing a field


I have 2 lists, one is a contact list (client, client title, address, etc.), the other is a list of meetings with these clients (client name, type of meeting, date, etc.).  The 2nd list has multiple entries for the same client.  I am trying to create a report that combines the data in these lists and displays them like this:

Client--Client Title--MeetingType1--MeetingType2




In addition to combining the list data, I also need to break up the Type of Meeting field and sum the number of different types of meetings for each client.  I added the 2 lists to a linked source, then inserted the data into a DVWP adding data from the 2nd list as a joined subview.


I tried this: xsl:value-of select="count(/dsQueryResponse/Rows/Row[@TypeOfMeeting = 'MeetingType1'])" but it just returns 0.  I'm not sure if that's the correct method though as I think it will return a count of ALL the rows, not the current row.  Any ideas would be appreciated!

Combining email and numeric regular expressions

Hi, I am using the following regular expression within an XSD to validate a combination of email ID's and six digit employee ID's separated by a semicolon (;). for example : vedansh.mm@fgfgfg.com;ghgh@ff.com;333333;555555 ^((\s*;?\s*[0-9a-zA-Z_]([-.\w]*[0-9a-zA-Z_])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})+\s*(;\d{6})*)*$ It works for the following vedansh.mm@fgfgfg.com;ghgh@ff.com;333333;555555 but does not work when the six digit number preceeds the email, like below 222333;vedansh.mm@ct.com;ghgh@ff.com;333333;555555;fhfhf@gggg.com or if the input contains only numbers, like 555555 What am I doing wrong. The numbers and email address count may or may not be the same. Thank you for all your help Vedanshu

Multiple statements in SSCE 3.5 SP2?

Hi all, I'm just wondering whether it's possible at all to execute multiple statements & multiple heterogeneous statements using the semicolon (";") separator.  SSCE balks at it right now if I issue via ADO.NET command text similar to the following (line separator is your typical \r\n): insert into Foo (id, name) values (1, 'foo1'); insert into Bar (id, name) values (1, 'bar1'); update Goo g set g.name = 'Goo1', g.fooId = 1, g.barId = 1 where id = 1; SQL Server Management Studio executes it just fine, which led me to believe that I could do it via ADO.NET. Can someone who knows please clarify?  What do I have to do in order to batch commands to ADO.NET? Thanks, Matthew

(SQL Server 2008) Exporting entire databases to SQL CREATE/INSERT statements

Hi All, I'm looking for a way to export SQL Server 2008 (Express or otherwise) databases to CREATE/INSERT statements.  I've seen a million threads (give or take) with instructions for creating large (often illegible) TSQL scripts for the task.  However, I'm hoping that this isn't the only way by which to do it.  I have need to regularly back up the data from existing MS SQL Server DBs (which are used by some of our standard apps) to various other MySQL and PostgreSQL databases (which are used by PHP and Rails web front ends).  I need to export them from MS SQL Server 2008 to a general format (i.e. INSERT statements) and perform regex edits on the file as necessary. FYI, I've written a few applications that connect to the various DBs over ODBC, etc. and transfer the data row by row.  You can image how painful this process is... I realize that there are many tools that do this.  However, most of them approach the issue from the standpoint of migration, and not that of regularly scheduled backups.  Also, this tool will need to eventually be distributed so having to purchase a license for the migration app for each person/group simply isn't feasible. Anyway, if you guys have a quality, straightforward solution to this issue, it would certainly be appreciated. Best.

Combining databases with Identity columns

(Using SQL Server 2005)  I have only a basic knowledge of SQL Server, but need to roll up 5 SQL databases into one database (I guess this is known as "replication"?).  These database are of similar structure and make use of an identity (or autonumber) column.  These id's are also referenced in numerous child tables.  To avoid collisions, this is my plan:   1.  turn off the identity feature of all the columns (but still keep condition of uniqueness) 2.  For each database, assign a unique range of identities (ie, db1 gets 1-500, db2 gets 501-1000, etc) and then renumber these columns accordingly.  The new id's should cascade to the child tables via the table relationships. 3.  Replicate or copy the data of all 5 databases into the new one.  There should be no collisions. 4.  Turn back on the identity feature of the appropriate columns, hopefully everything works as before. After this is done we hopefully can get rid of the 5 original databases and proceed with just one. Should this work and/or is there a better way to do this?  

configure both select and Update statements in ADO.NET

 i would like to retrieve a value with select and perform a calculation and then save using update in the same batch code?  

Cannot see output from Print statements executed within SQL Server Management Studio

When I execute a Print statement in a query within Management Studio, I get no output in the Results Pane (Messages tab).  I've worked with Oracle mostly and there I had to enable dbms output in the database session AND enable output within the tool I was using (Quest SQL Navigator) before any output could be seen.  Is there something similar that I need to do when working with SQL Server and SQL Server Management Studio? FYI, I DO get output if I use RAISERROR('yadda',16,1), but nothing if I use Print 'yadda'. I appologize if there's an answer to this already in the forums, but I searched and couldn't find it. Thanks, Neil

Multiple sql-statements in one transaction

Hi - I've two sql-statements - two inserts statements.The first one creates a person and the next creates an entry in another table with the person id as reference - everything works fine but I've been looking at my code and would like to know how I should wrap it up before firing the statements.I keep it all in one transaction - if the creating of the person fails or the other operation I need to rollbackMy question is:Should I use the same SqlCommand object to fire both statements? At this point I create a new instance for each statement - but isn't it possibly to use the same SqlCommand object, the same SqlConnection and wrap it into the same SqlTransaction?What is best practise in situations like this?

Can't get Distinct work, when combining fields from inner joined tables

Hi to all.I have a users table, each user has a session and each session has multiple parameters.I would like to retrieve all params for a specific user and get the paramID from the params table and the date submitted from the sessions table.This is the linq to SQL query so far:var items = (from param in db.Params join session in db.Sessions on param.SessionID equals session.ID where userID.Equals(session.UserID) //userID is the function argument orderby session.DateSubmitted descending select new { ParamID = param.ID, DateSubmitted = session.DateSubmitted }).Distinct(); I have noticed that when the DateSubmitted is fetched, i have multiple instances of a param in the result set, meaning that the Distinct does not work as expected. If i remove it like this:var items = (from param in db.Params join session in db.Sessions on param.SessionID equals session.ID where userID.Equals(session.UserID) //userID is the fu

SSIS SQL SP and Update statements

I have a SP that does a bunch of selects and some updates, it ends with doing a select from several temp tables its built, and then doing the update.  My questions is, when I run it manually for the first time i get all the records i would expect.  If i run it from SSIS for the first time i dont get the results i expect, its like the updates that are in the SP have already occurred and so it reduces the number of records I would expect to get back.  My question related to the validation peice, does it actually run the SP when it validates, if it does it would answer my question i guess since its doing the updates.  If it doesnt, not sure hot to explain the diff

using pre-processor directives to turn off console.writeline statements?

I have a DOS console application that when processing files will output information to the screen.This is a nice feature when I run the program. But when in production it would somehow be niceto turn of all of my Console.WriteLine statements.  Because unlike my test environment, in production,several hundred files will be processed, and printing out console information will slow my console applicationdown. (I think. You see the console application is set up to run as a scheduled task everyday at 12 noon) So here is my question. Can the console.writilines be turned off in production using C# pre-processor directives?I have read about the Pre-Processor directives, but something is not clicking in regards to how I can apply it.So I am hoping I can apply it in the situation I just described.

Error: "Select statements included within a function cannot return data to a client"

hi all, Not sure if there is an easier way to do this but this is my first ever Function I created so far. I am getting the error: "Select statements included within a function cannot return data to a client" All I am trying to do is ...if the date is NOT passed then apply NULL as the default value and run the SELECT statement. If the date IS NOT null then run a different SELECT statement. CREATE FUNCTION [SchemaTest].[fn_Test] ( @instance as uniqueidentifier ,@date as datetime = null ) RETURNS varchar(8000) AS BEGIN If (@date is null) --@date = null ?? Begin Select * From Uds.RealtimeLogging Where instanceID = @instance End Else Begin Select * From Uds.RealtimeLogging Where instanceID = @instance and [timeStamp] > @date End Return @stepIds END Thank you!JCD
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend