HI
I am using a webform and a SQLDataSource, I am using query builder its for a grid view. I want to get a certain amount of characters frm a column in the table just say 1 line from a paragraph. How do I do it in query builder? is it possibe if no, how would i do it?
Thanks in Advanced!
NewbieProgrammer
To get first 100 characters modify your SQL to look like this:
SELECT SUBSTRING ( myColumn , 1 , 100 )
FROM mytable
Related
I am not able to search the middle part of string using fulltext search index for eg:there was a string "I like music" i was not able to search for like which is in the middle part of string..
Try LIKE operator.
SELECT
*
FROM
YourTABLE
WHERE
ColumnName LIKE '%like%'
Use Like keyword in query as follows:
select * from tablename where col like '%like%'
Here is the tutorial of like in sql:
http://www.w3schools.com/sql/sql_like.asp
Here is the MSDN:
http://msdn.microsoft.com/en-us/library/ms179859.aspx
Hope its helpful.
Well, in order to still use the fulltext index and to avoid a table scan, try this
select *
from yourTable
where contains (ColumnName,'like')
and (ColumnName not like 'like%' or ColumnName like '_%like%')
However, the query optimizer might decide that a full table scan is more effective.
Check if statistics of your table out of date, especially check the statistics relates to your fulltext index. Since you are using SQl Server 2008, so, you can query DMV to get statistics information of your index or using DBCC to see the statistics detail information
DBCC SHOW_STATISTICS ("[schema].[table]",indexname);
Check the first return result, [Updated], [rows], [rows sampled], if the statistics out of date, or [rows sampled] far less than [rows], which many cause SQL Engine decided to use table scan instead of using your index.
I have a DOB column in a table that is currently in use. See below.
I want to select just the Year from that DOB and display that on a Listbox (or any appropriate interface on a page). We are not using SPs. So I will probably coding SQL directly from the page or using SQL datasource. Using LINQ is alright if that can be done in it.
So please someone suggests me how this can be done.
Thanks a lot.
Use the YEAR function in your SQL statement.
SELECT YEAR([DateOfBirth])
FROM MyTable
SELECT DISTINCT Year(DateOfBirth) AS Year FROM MyTable ORDER BY Year
By including the DISTINCT keyword you will prevent duplicates in your list and by adding the ORDER BY clause the years will be sorted ascending. You can then bind the result to your listbox.
In your TSQL, write this:
SELECT YEAR(DateOfBirth), ...
FROM ...
I have a SQL Server 2005 database in which I have some tables contain Arabic text. The datatype for those fields is NVARCHAR(n).
The Arabic text inside the table is appearing properly, and when selecting using select clause, they appear properly.
The problem is that searching for Arabic text with where clause results in 0 rows.
select * from table_name
where name=#name
This retrieves no rows, where there is a name with this value.
When we use it like:
select * from table_name
where name=N’Arabic_Text’
Then it works, but how we can pass searching text from front end to back end.
Can you please guide me on how to write the query?
PS
In code behind i wrote:
Dim UserName As String = "N'" & txtLogin.Text & "'"
Dim _dtLogin As DataTable = oUser.UserLogin(UserName)
it returns 0 rows even if that user exist in database.
You need to concatenate your query and you need to use N before value to check because of unicode value
Considering this part: select * from table_name where name=#name
If this is a stored procedure, you need to modify it to be like this:
select * from table_name where name=N#name
give it a try and let us know if it worked.
Maybe i should do this in C# but i have more then one row with linkId X. I would like to remove it but i am unsure how. In code i could just use a foreach from 0 to n and remove any found rows with a greater (or !=) id but thats in code. Is there a less difficult way of doing it using sqlite?
Assuming the table's name is tableName and there is a primary key field named id, the following sql would do it. I think the following SQL query is general enough and should be able to be executed under any database engine.
delete from tableName
where id not in (
select min(id) from tableName
group by linkId
)
How do I split data into pages on ASP.Net?
I'm looking for something like what Google does when you have too many search results and it splits them into x number of pages.
It would depend entirely on the content. If it's a simple datagrid you can use the built in datagrid paging. If the data is coming from SQL though, I'd advise building a generic "paging control" and using the paging functionality of SQL to only pull back the data you want to see.
If it's SQL 2005 (or above) paging is nice and easy:
SELECT Description, Date
FROM (SELECT ROW_NUMBER() OVER (ORDER BY MyCol DESC) AS Row, Desc, Date FROM MyTable)
AS MyTableWithRowNumbers
WHERE Row >= 1 AND Row <= 10
A paginating datagrid or a repeater would be your best options.
Use a GridView and the LinqDataSource.
It will do it all for you.
See:
http://msdn.microsoft.com/en-us/library/bb470363.aspx
and:
http://msdn.microsoft.com/en-us/library/bb547113.aspx