Can Anyone Write A Simple Query To Search For NULLs
Apr 30, 2008
Hello ALl, can anyone please tell me how to search for NULLS.
like i know one method....
select * from table
where col = 'NULL'
Hello ALl, can anyone please tell me how to search for NULLS.
like i know one method....
select * from table
where col = 'NULL'
Hello all,
I am writing Stored Procedure to perform various kind of search on Database Tables.
I having requirement like Exact Phrase,Any of the word,All Words and Refine search.
I am using Full text Queries for this.
I am stuck with "All Words" search query. Can anyone please guide me how to write query to perform this kind of search. Below is the little elaboration about All words search.
Query should return all the results which contain all the words from search phrase irrespective of order.
e.g. if i search am searhing "Green House Effect" phrase then query should return all the records which having these three words in any order. like Green fds dfasd House fdsd fdsdf Effect or House fds fds Green Fd fds Effect or Effect fsda fdsa Green fd fdsa HOuse.
all the records selected by query must have all words exist in any order.
Suggest me the logic or query or any SQL Server keyword which i can use for this.
Please do the needful ASAP. Thanks.
Hi,
I'm writing
small search engine for my page. I need SQL query that could do this:
Source:
tblColours
------------
Red
GreenRed
White Red
Yellow
Blue Green
Yellow RedF
Search
string: Red
Required
results:
Red
White Red
Yellow RedF
As you can
see I need all occurrences of word Red and word Red* but I don’t need *Red or
*Red* so I can't use LIKE %Red% :(.
P.S. Sorry
for my English.
Fizikas.
I have a table that has these columns:
LinkID, LinkURL, TimesRedirected
I have a webpage that keeps track of the url's of where the users are coming from. When they redirect to the page, the page will:
If the url of the previous page isn't in the database, add it
Otherwise, add to the TimesRedirected column.
What I really need is to find the entries that have the word LVAD but on either side there should be a space chartacters.In other words I don't want to see the following coming from the query "SILVADENE ([PHI] SULFADIAZINE)"How can we write this query to search only for any entry that has the word " LVAD " ?
Select top 100 * FROM tbl_abc
where
AIMS_Value like '%LVAD%'
I am trying to write a simple search page that will search all the fields in a database to find all records that match a user input string. The string could happen anywhere in any of the fields. I have a dataset and can write a query but am unsure what the format is for this simple task. I figured it would look like this:
SELECT Table.*
FROM Table
WHERE * = @USERINPUT
But thats not working. Can someone help.? Thanks..
I'm looking to write my own simple SQL Client via TCP/IP. We have some hardware that does not run an OS of sorts, but I can create TCP Connectons. We's like to be able to Query our SQL Server with this hardware.
The SQL Servers we are talking to are MS SQL2000 and MS SQL 2005 both via TCP port 1433. We can telnet to the port of the SQL Server. Any resources to the SQL Protocol you could pass along would be great.
Thank you,
Scott<-
Hi all,I'm very new to ASP.NET stuffs, I'm trying to write a Search function for my website... I have two text boxes, one if called "SongTitle" and the other is "Artist"... Now I need to populate the GridView to display the result, based on the input of the textbox... So if only the "SongTitle" have input, it will search for the Song Titles on the database... if the Artist is searched, then it will return the artist... If both text boxes have value in them, then it need to check for both fields in the database and return the correct item... For the "Artist", I have 2 columns in the Database (originalArtist and performer), so for the Artist select statement, it need to check both columns on the table, if any of them match then it will return the item. Any help would be greatly appreciated,Thank you all,Kenny.
View 15 Replies View RelatedI want to test some times it takes for a proc to run. Since I work for a large company, I rarely have access to the SQL server in a capacity where I can use profiler and such. Are there any quick and easy ways to just surround blocks of code in a T-SQL statement to get an accurate reading on how long it takes?I.e., if I surround with GETDATE() before and after, does that also measure the round trips to the server, or just the execution time.I want to just compare some different methods and see what is quicker. THX.
View 4 Replies View RelatedHi, Im trying to create a simple search page to return a list of products from a table in a sql database. Id like to be able to search a product description column in a table I have called products using the contents of a text box. I was wondering how i can go about getting the search to check for all words the user types in rather than just a single word or an exact phrase. Im currently using the following sql query
SELECT [product_title], [product_description] FROM [products] WHERE ([product_description] LIKE '%' + @product_search + '%')
this works fine for single words and exact phrases but if i had product called 'fred w bloggs' and i enter 'fred bloggs' it will not return anything.
Please could anyone suggest how i shoud go about this?
Im not sure if my web hosting company will enable full text search or will this be required?
Thanks for any help!
pete_ (very new to asp.net!)
Hi all I need to implement a search function in Asp.net. Its nothing complicated, just find out whether a value exists in a particular table and return a boolean accordingly. However, the table has about 300,000 records. Is simply querying the table from the web (SELECT barcode FROM tblProducts where ID=123) the best way considering the releant column has been indexed.Any pointers would be appreciated. Thanks
View 4 Replies View RelatedHello new in sql and asp.net here.I have this Select * from InvoiceHeader where TransactionDate > '03/16/2008' That code isn't working instead of returning a row with a transaction date that is greater than 3/16/2008 what it return is all the row. How can fix this? Thanks!
View 9 Replies View RelatedI have a table of articles:
-------------------------------------
Articles
-------------------------------------
ID | Date | Headline | Body
-------------------------------------
I'm trying to write a stored procedure that will search for a given keyword. Here's what I have:
CREATE PROCEDURE sproc_SearchArticles
(
@keyword varchar(50)
)
AS
SELECT ID, Date, Headline, Body
FROM Articles
WHERE Body LIKE %@keyword%
ORDER BY Date DESC
RETURN
That keeps giving me an error. If I put quotes around it, it will literally look for the term @keyword anywhere in the body.
Hello all, I am trying to build a simple search page using SQL Server 2005, Visual Web Developer in C#.I have enabled Full-Text Search on my DB and created the catalogs and indexes, but I am lost on the next step to build a search form that calls the data based on the users input in a textbox. Any suggestions? Thanks!Travis
View 3 Replies View RelatedI'm not trying to do anything too fancy; given a string, I just wanna see if anything in the column of my database matches the string. I'm using an SQL query that takes a string, then selects the data using LIKE %searchword%.This works fine when the user enters only one word. But I guess you can see that a problem arises when they enter more than one word.So how can I implement a very simple search that will take more than one word?
View 5 Replies View Relatedhello I have this code Select Waste.WasteName AS [Waste Name], InvoiceDetail.Volume, Branch.BranchLocation AS [Branch Location] From InvoiceHeader INNER JOIN InvoiceDetail ON InvoiceHeader.InvoiceNo = InvoiceDetail.InvoiceNo INNER JOIN Waste ON InvoiceDetail.WasteID = Waste.WasteID INNER JOIN Branch ON InvoiceDetail.BranchID = Branch.BranchID Where WasteName = 'Sludge' AND InvoiceDate >= '" + TextBox1.Text + "' AND InvoiceDate <= '" + TextBox2.Text + "'; The problem is everytime I will search for example InvoiceDate 03/27/2008, I need to add one day for example --> 03/28/2008 for me to be able to get that Invoicedate 03/27/2008.. What's do you think is the problem with my code? Thanks!
View 9 Replies View RelatedI'm very new to SQL so please forgive my ignorance...
I've made a simple .net search page which queries an sql database with the following query, (in a stored procedure):
SELECT Category, Number, RegisteredUser, DeptName, Surname, Forename, Site, IDFROM tblTelephonesWHERE (@surname IS NULL OR Surname LIKE @surname) AND (@site IS NULL OR Site = @site) AND (@deptname IS NULL OR DeptName LIKE @deptname)
This works fine, as expected if i leave fields null or enter an exact match, but I (of course) have to add a wildcard in my search string for a wildcard search. For example, looking for 'duncan' i need to enter 'du%' or 'duncan'.
What I really want is for all searches to have wildcards behind them so only the first few characters need be inputted, and I could just search for 'd' or 'dun' without adding the '%' to get 'duncan'. I think I am aware of the implications of this approach and do want to go ahead as there are only about 850 records.
Any help or links to useful articles would really be greatly appreciated.
This question probably applies to Visual Web Developer but I don't know if it belongs in this Forum or that, sorry if you have to move it.
Hi there kind person reading this
I've created a stored procedure in SQL2000 that selects records where (name = @name) AND (site = @site). It works as I have tested it with Enterprise Manager.
I have also created a page with VWD that has a drop-down list populated with the site records and a text box. I have put an SQL data source on the page that is configured to select from the stored procedure. However, I can't set the @name and @site variables to collect from the ddl and txtbox through the wizard! I've tried selecting a Control as the source for @site but neither the ddl or txtbox appear in the control dropdown list. So I want to crack it with handwritten code.
Does anyone know of a post or article that can help me link the ddl and txtbox to a search button, which calls the stored procedure with the chosen variables allowing me to put the returned data into a gridview? I've been through a great walkthrough for VWD (Student Activities) but it doesn't seem to apply to the latest version - or there's something wrong with my (seems fine though) instalation. Thanks if you can help, I owe you a
I have a table of news articles:
-------------------------------------
Articles
-------------------------------------
ID | Headline | Article
-------------------------------------
I'm trying to write a search function that will search through the text in the Article column. Here's my stored procedure:
ALTER PROCEDURE sproc_SearchNews
(
@keyword varchar(50)
)
AS
SELECTID, Headline, Article
FROMArticles
WHEREArticle LIKE '%' + REPLACE(@keyword, '%20', '%') + '%'
RETURN
There's a few problems with this however...
1. If I enter "Dog" into the search, it will skip over the article if it contains "dog". I need to convert the search term and the article text to lowercase.
2. If I enter "iron" into the search, it will find articles containing "iron", but it will also find articles containing "environment". How can I fix that without affecting my multiple word search in the WHERE clause?
Hello,
I have a search form in an ASP.NET/VB page. The form has the input text box and the button "search". The keywords are passed in the URL to results.aspx.
Here is an example of what I get in the URL, when I write the keywords "asp", "book" and "london" in the input text box and click "search":
results.aspx?search=asp%20book%20london
The database table has 3 fields: "id", "title" and "description".
I want to display all the records where at least one of the keywords is found in any of the 2 fields "title" and "description".
1. I suppose I need to get the words out of the URL to be used by SQL.
Maybe: string[] searchString = request.queryString("search").split('search'); ???
How can i make this run when page loads? I supose i need it. Right?
2. How should the SQL look? I supose i need to use the "Like" command
SELECT * FROM books WHERE title LIKE ...
But how to I use it if I can have 1, 2, 3, ... keywords?
Can someone help me?
Thanks,
Miguel
I want to write a statement something like this
SELECT Add_Date, File_No FROM dbo.File_Storage WHERE (File_No = 11/11/1234/)
But i want the search to ignore the first 2 digits so that it will return e.g
10/11/1234, 09/11/1234 so that it's only matching the last part
Any Help Would be greatly appreciated Thanks
I'd like to build a simple search engine against Sql Server. Does .NET Framework provide some class to help in this task? From what I've heard there is an interface which implements it..
View 1 Replies View RelatedHi - I'm short of SQL experience and hacking my way through creating a simple search feature for a personal project. I would be very grateful if anyone could help me out with writing a stored procedure. Problem: I have two tables with three columns indexed for full-text search. So far I have been able to successfully execute the following query returning matching row ids: dbo.Search_Articles @searchText varchar(150) AS SELECT ArticleID FROM articles WHERE CONTAINS(Description, @searchText) OR CONTAINS(Title, @searchText) UNION SELECT ArticleID FROM article_pages WHERE CONTAINS(Text, @searchText); RETURN This returns the ArticleID for any articles or article_pages records where there is a text match. I ultimately need the stored procedure to return all columns from the articles table for matches and not just the StoryID. Seems like maybe I should try using some kind of JOIN on the result of the UNION above and the articles table? But I have so far been unable to figure out how to do this as I can't seem to declare a name for the result table of the UNION above. Perhaps there is another more eloquent solution? Thanks! Peter
View 3 Replies View RelatedI've got an nvarchar(max) column that I need to transform with some simple text processing: insert some markup at the very beginning, and insert some markup just before a particular regular expression is matched (or at the end, if no match is found).
Since the SSIS expression language doesn't support anything like this, is a Script Component the only way to go? Does Visual Basic .NET provide regular expression matching?
Thanks!
Hi,how do I do a simple formula, which will search a field for specialcharacters and return a value.If it finds "%" - it returns 1elseIf it finds "?" it returns 2endIf this is the incorrect newsgroups, please direct me to the correct oneregards Jorgen
View 2 Replies View RelatedHi I have a query, what I would like to do is create a column that takes the results in two coulms and add them together:
Col A Col B Col C
Row1 1 1 2
Row2 2 3 5
Here is the query
declare @t table( player_name varchar(100), BuyIn int, TopUp int, ReBuy int, Winnings int, Events int, Test int)
INSERT INTO @t (player_name, TopUp)
SELECT Player_name, SUM([Top-ups]) AS TOPUPS
FROM (SELECT Event_data.Transaction_type, Players.Player_name, Events.Top_up, Event_data.Transaction_value,
Events.Top_up * Event_data.Transaction_value AS [Top-ups]
FROM Event_data INNER JOIN
Events ON Event_data.Event_id = Events.id INNER JOIN
Players ON Event_data.Player_id = Players.Player_id
WHERE (Event_data.Transaction_type = 2)) AS Topups
GROUP BY player_name
INSERT INTO @t (player_name, ReBuy )
SELECT Player_name, SUM([Re-buys]) AS REBUYS
FROM (SELECT Event_data.Transaction_value, Players.Player_name, Events.Rebuys, Event_data.Transaction_value * Events.Rebuys AS [Re-buys]
FROM Event_data INNER JOIN
Events ON Event_data.Event_id = Events.id INNER JOIN
Players ON Event_data.Player_id = Players.Player_id
WHERE (Event_data.Transaction_type = 3)) AS REBUYS
GROUP BY Player_name
Insert into @t (player_name, BuyIn)
SELECT dbo.Players.Player_name, SUM(dbo.Events.Buy_in) AS BuyIn
FROM dbo.Players INNER JOIN
dbo.Event_data ON dbo.Players.Player_id = dbo.Event_data.Player_id INNER JOIN
dbo.Events ON dbo.Event_data.Event_id = dbo.Events.id
GROUP BY dbo.Players.Player_name, dbo.Event_data.Transaction_type
HAVING (dbo.Event_data.Transaction_type = 1)
ORDER BY SUM(dbo.Events.Buy_in) DESC
Insert into @t (player_name, Winnings)
SELECT dbo.Players.Player_name, SUM(dbo.Event_data.Transaction_value) AS Winnings
FROM dbo.Players INNER JOIN
dbo.Event_data ON dbo.Players.Player_id = dbo.Event_data.Player_id
GROUP BY dbo.Players.Player_name, dbo.Event_data.Transaction_type
HAVING (dbo.Event_data.Transaction_type = 1)
insert into @t (player_name, Events)
SELECT dbo.Players.Player_name, COUNT(dbo.Event_data.Place) AS Expr1
FROM dbo.Players INNER JOIN
dbo.Event_data ON dbo.Players.Player_id = dbo.Event_data.Player_id INNER JOIN
dbo.Events ON dbo.Event_data.Event_id = dbo.Events.id
GROUP BY dbo.Players.Player_name
HAVING (NOT (COUNT(dbo.Event_data.Place) IS NULL))
insert into @t (player_name, test)
select player_name, ((TopUp) + (Rebuy)) as Test
from @t
SELECT player_name, min (BuyIn) as BuyIn, min(TopUp) as TopUps, min(ReBuy)as ReBuy, min(Winnings) as Winnings, min(Events) as Events, min(test) as test
FROM @t
GROUP BY player_name
ORDER BY BuyIn DESC
--ORDER BY TOPUPS DESC
END
THis is where I attempt to add the coloms but I get a null result
insert into @t (player_name, test)
select player_name, ((TopUp) + (Rebuy)) as Test
from @t
any help would be great.
I am trying to emulate the "Find unmatched Records" Access Query using DTS. I have a small table with a list of codes that I need to use to exclude records in my text export.
I have created a left outer join and set the criteria for the joined field in the 'right' table to be null. I am repeatedly getting no records as a result.
Wouldn't the joined field in the right table for unmatched records by default be null? I'm stumped as to why this seamingly simple process won't work for me. I have attached the select statement for your review.
Any help would be greatly appreciated.
I have a table called "alert" and in this table, for each columns there are data as 1 , or 0 or NULL. how do I write a query to just give me data's with "1" in them not the NULLS or 0?
View 3 Replies View RelatedThis is my problem, i have 2 tables: one table that hold data, having id as identity, say table (id, content), the other table have 2 columns: (id, number). The second table number column refer to the id in the first table. i want to build a query that get the data from the first table that correspond to a specific id in the second table, not only this i want to get the previous, the current and the next item.
For example: if table_data, table_info is first and second tables, something that can do it is :
DECLARE @i int
SELECT * FROM table_data WHERE id in (@i -1, @i +1, @i)
The problem here if @i, @i+1 or @i-1 doesn't exist the column will not be returned, i want to get a result similar to
id, content
25 null
26 null
27 #some content#
or
34 #content1#
35 #content2#
36 #content3#
so my problem is that nulls doesn't appear, i thought about using OUTER JOIN, but the problem is that outer join take tables, not (@i -1, @i +1, @i), so if only i can make somehow the outer join use these values, i think it works.
Any help please, and thanks in advance
Is there a way to set SQL Server 2005 Express so that I can return null values? For example, the following query will not return any values:
SELECT *
FROM tbl_form_values
where fldVALUE IS NULL;
it does return values with:
SELECT *
FROM tbl_form_values
where fldVALUE = '';
I have an Oracle background and all null values are true nulls not empty strings. I would like to be able to use the first query. Also other functions such as COALESCE work very nice with nulls. I can do the following in Oracle but not in SQL Server:
SELECT fldID, fldMID, fldFID,
COALESCE(fldVALUE, 'n/a');
FROM tbl_form_values
This will return the values in fldVALUE if they are available and n/a for all NULL values.
Any help would be appreciated.
Thanks,
E
When i do a select on my emplee table for rows with null idCompany i dont get any records
I then try to modify the table to not allow a null idCompany and i get this error message:
'Employee (aMgmt)' table
- Unable to modify table.
Cannot insert the value NULL into column 'idCompany', table 'D2.aMgmt.Tmp_Employee'; column does not allow nulls. INSERT fails.
The statement has been terminated.
This sux
is there an elegant way to use one equals sign in a where clause that returns true when both arguments are null, and returns true when neither is null but both are equal and returns false when only one is null?
View 4 Replies View RelatedI have two SSIS packages that import from the same flat file into the same SQL 2005 table. I have one flat file connection (to a comma delimited file) and one OLE DB connection (to a SQL 2005 Database). Both packages use these same two Connection Managers. The SQL table allows NULL values for all fields. The flat file has "empty values" (i.e., ,"", ) for certain columns.
The first package uses the Data Flow Task with the "Keep nulls" property of the OLE DB Destination Editor unchecked. The columns in the source and destination are identically named thus the mapping is automatically assigned and is mapped based on ordinal position (which is equivalent to the mapping using Bulk Insert). When this task is executed no null values are inserted into the SQL table for the "empty values" from the flat file. Empty string values are inserted instead of NULL.
The second package uses the Bulk Insert Task with the "KeepNulls" property for the task (shown in the Properties pane when the task in selected in the Control Flow window) set to "False". When the task is executed NULL values are inserted into the SQL table for the "empty values" from the flat file.
So using the Data Flow Task " " (i.e., blank) is inserted. Using the Bulk Insert Task NULL is inserted (i.e., nothing is inserted, the field is skipped, the value for the record is omitted).
I want to have the exact same behavior on my data in the Bulk Insert Task as I do with the Data Flow Task.
Using the Bulk Insert Task, what must I do to have the Empty String values inserted into the SQL table where there is an "empty value" in the flat file? Why & how does this occur automatically in the Data Flow Task?
From a SQL Profile Trace comparison of the two methods I do not see where the syntax of the insert command nor the statements for the preceeding captured steps has dictated this change in the behavior of the inserted "" value for the recordset. Please help me understand what is going on here and how to accomplish this using the Bulk Insert Task.