sql

Difference between not equal and greater than for a number

I have a query: select * from randomtable where randomnumber <> 0 The column "random_number" will never be a negative number. So, if I write the query as: select * from randomtable where randomnumber > 0 Is there any major difference? ...

Efficient query to lookup stuff in a word index

I have two tables defined like this: Page(id), Index(page_id, word) page_id in Index is a foreign key to Page so that each Page is connected to a group of Index entries. The Index table is a index for the Page table so that you can do fast text searching. E.g: SELECT page_id FROM Index where word = 'hello' Would select all page_id'...

self joining a table

Basically when do we need a self join on a table? ...

Parameter not passed

hi.. today i fot one error. i am not able to understand why it is. i hope somebody will help me here my method is public UserFamilyInfoBO GetUserFamilyInfo(Int64 UserId) { try { DataSet Ds = new DataSet(); SqlCommand Cmd = new SqlCommand("GetUserFamilyInfo", Cn); ...

Creating php arrays from sql queries

Hiya, I'm trying to create an array of arrays so I can build a dynamic menu, but I'm getting lost amongst the code. My output looks like this: $menu = Array ( [0] => Array ( [text] => Home [class] => 875 [link] => //Home [show_condition] => TRUE [parent] => 0 ...

SqlBulkCopy failing with String conversion issue

I have a view which generates a number of columns which I want to bulk load into another table which has identically named columns. This procedure worked fine when I was looping over the SqlDataReader and doing an insert with SqlParameters using a SqlCommand each time. Obviously for many 100000s of rows, this was too slow. I switched t...

the row no in query output

I have a numeric field (say num) in table along with pkey. select * from mytable order by num now how I can get the row no in query output of a particular row for which I have pkey. I'm using sql 2000. ...

Help needed in writing sql query

how can i write a query for this? I'm not an expert to write this much of complex queries in sql. I forgot to mention bid 3, 4 here Thank you, Jestges ...

Linq to LLBLGen query problem

Hello, I've got a Stored Procedure and i'm trying to convert it to a Linq to LLBLGen query. The query in Linq to LLBGen works, but when I trace the query which is send to sql server it is far from perfect. This is the Stored Procedure: ALTER PROCEDURE [dbo].[spDIGI_GetAllUmbracoProducts] -- Add the parameters for the stored procedure...

Don't use DISTINCT when you have or could use GROUP BY

According to tips from MySQL performance wiki Don't use DISTINCT when you have or could use GROUP BY Can somebody post example of queries where GROUP BY can be used instead of DISTINCT? ...

Entity framework, getutcdate()

Hi, Can I use the SQL-function getutcdate() from entity framework to set a date field in the database when saving an entity object? regards Freddy ...

Question regarding many-many relationships

Hi, I have a very simple problem for which though I have a solution but I want to know how others tackle it effectively. Assume we have a User table, and a Role table. Each user can have multiple roles and vice-versa (many-to-many relationship). This relationship is stored in a cross table: UserRoleMapper (UserID, RoleID). Now I have ...

Does SQLite support replication?

In an application which embeds SQLite3 and uses an in-memory database, is it possible to replicate the database between two running instances of the application? I could do this by hand with a homebrew protocol duplicating all my DB accesses, but it seems like something that should be done inside the DB layer. ...

How mapping of cities in a country-map is done? ( so users can search for ads nearby their cities )

I have a classifieds website. The users first have to specify their 'area of search'... I want to add a function where users also can check a checkbox to find ads 'close' to their selected 'area'. But I don't know how to 'mapp' or 'link' the areas together in a smart way. I need some advice on how to do this... For example, how is 'ra...

Can I use always INSERT ....ON DUPLICATE UPDATE for simple updates/inserts?

(MYSQL) Is there any significant performance differences, or other reasons not to use the INSERT ... ON DUPLICATE UPDATE sql to update by PK/insert new stuff? ...

What do you use for organizing SQL snippets?

What do you use for organizing SQL snippets? I've been using a directory structure with separate SQL files. I work as an consultant and the customer wants some of their people to have an "easier" interface for organizing/searching for SQL snippets than directories and operating system search. What solutions are others using? Seems lik...

How to select records from last 24 hours using SQL?

What where clause should be use to get records from the last 24 hours? ...

C# SQL export (OutofMemory issue)

I am trying to bulk export out of a sql table, the code works fine. Nothign wrong with it at all, the problem resides in exporting 50 columns at 2.7million rows. Can anybody help me with the OUtofMemory exception. I know why it's happening because it tried to read it all to memory then write, but i'm not sure how ot break it up to rea...

SQL conditional union

Question: I have an SQL function which returns a list of files now I should join an additional list to that list with an union, but only if the user is admin. Is that possible? Something like: CREATE FUNCTION tfu_CMS_Process(@bIsAdmin bit ) -- Add the parameters for the function here RETURNS TABLE AS RETURN ( SELECT * FROM TABLE1 ...

PHP - Show results from different queries on one page, either or, not all at the same time

Not sure if that was the best way to phrase what I'm trying to do. Here goes: I want users to be able to show results form my DB based on three different tables, one at a time. I have the queries ready, but only want to show one result on the page at a time, based on what the user clicks. The queries are based on 3 different tables. Th...