473,418 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

How can I get 2 rows as first reply when databse has more rows with same keywords?

Hi, my database has 4 colums: name, adres phone and fax

I'm running this query:

SELECT DISTINCT '$sender',MSG = substring ((SELECT RTRIM(name)+','+RTRIM(street)+' t:'+RTRIM(telno)+' f:'+RTRIM(faxno)+' - ' FROM autodatabase WHERE
name LIKE '$keyword%' FOR XML path(''), ELEMENTS),0 ,500) FROM
autodatabase

I want the first reply to be the first 2 rows of what has been found.
I get all the rows with the same keyword in the database.

I've run:

SELECT RTRIM(name)+','+RTRIM(street)+' t:'+RTRIM(telno) AS search
FROM autodatabase
WHERE name LIKE '$keyword%'

But now it doesn't break the rows. It displays it as one long sentence

How can I break the rows but get 2 rows when asking for data en which string do I use to ask for the next rows (row 3 +4) with the same keyword?

Thanks
Priscillamuis
Feb 25 '10 #1
9 1466
OraMaster
135 100+
Try using TOP keyword.
Feb 26 '10 #2
Do you also think I should use BEGIN LOOP en END LOOP?
I SELECT RTRIM(name)+','+RTRIM(street)+' t:'+RTRIM(telno) AS search
FROM autodatabase BEGIN LOOP
WHERE name LIKE 'TOPkeyword%'
ORDER BY name ASC

I also don't know if I should use @@ROWCOUNT =2 to use as command to break the data after 2 lines, but to go on with the list I don't know if I should use CONTINUE and stop the script with END LOOP.

WHAT do you think?
Feb 26 '10 #3
OraMaster
135 100+
TOP is something different. It is being used like

Expand|Select|Wrap|Line Numbers
  1. select TOP 100 * from <tablename>
Feb 26 '10 #4
Ooh, ok. But I don't know how many rows will be found? Every search will be different. If I don't know the number of rows, what syntax do I use?
SELECT TOP '%' * from autodatabase?
Feb 26 '10 #5
sashi
1,754 Expert 1GB
Why not create a simple stored procedure for this purpose?

Count number of rows
Expand|Select|Wrap|Line Numbers
  1.   SELECT COUNT(*) FROM tblName WHERE fldName LIKE = 'what_u_want_to_search'
  2.  
Kindly refer to below attached link,

Learn T-SQL
Feb 26 '10 #6
I've already tried this. It works but it display's the row count. I don't want the row count.
I want to see/ view the information that's in the rows.
How do I do that?
Feb 26 '10 #7
sashi
1,754 Expert 1GB
I want to see/ view the information that's in the rows.
What do you mean by information in the row? Can't see the information with a simple [SELECT] statement?
Feb 27 '10 #8
Sorry, let me rephrase: I want to find the rows with the keyword in it, eg 10 rows with red in database. But I want to display 2 rows at a time without losing the whole list e.g red blue and red yellow. The other red green, red magenta, red white etc) The query should divide the list into 2 rows of 160char en let the list just loop on until I'm back on top again.
Mar 2 '10 #9
ck9663
2,878 Expert 2GB
You have to handle that on your front-end, not on the back-end.

Happy Coding!!!

~~ CK
Mar 2 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Rowland Hills | last post by:
I have a table which is returning inconsistent results when I query it! In query analyzer: If I do "SELECT * FROM TABLE_NAME" I get no rows returned. If I do "SELECT COL1, COL2 FROM...
20
by: WindAndWaves | last post by:
Hi Gurus I was wondering if you can send me in the right direction: I have a table with about 300 rows. I want to make all of them invisible and when a user enters a code in a form then make...
13
by: Lyle Fairfield | last post by:
Suppose there are four identical rows in a table, save for some unique id which identifies each row. For example, John Doe and his three clones live in the same home, share the same dob, name,...
15
by: Paul T. Rong | last post by:
Hi everybody, This time a very very difficult case: I have a table "tblStudent", there are 50 students, I also made a form "frmStudent" based on "tblStudent", now if I don't want to show all...
4
by: Laura | last post by:
Here's the situation: I'm trying to use an update query to copy data from one row to another. Here is the situation: I have 5 companies that are linked to each other. I need to show all 5...
3
by: Carolyn Vo | last post by:
I have a datagrid in my web control class that I am trying to get the current rows displayed for. I have enabled paging on the datagrid so if the user is currently on page 3 of 8, and if I have...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
9
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like...
11
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to...
17
by: pbd22 | last post by:
Hi. How does one return a range of rows. I know that "Top 5" will return rows 0 - 5 but, how do I get 6 - 10? thanks
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.