sql

What is wrong with this connection string?

Can any one help me with this connection string. I can't manage how to fix. Dim constring As String Dim con As SqlCeConnection Dim cmd As SqlCeCommand constring = "(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + \\database.sdf;Password=pswrd;File Mode=shar...

When it comes to updating all rows in a table, does the method of locking matter for performance?

Question is a follow up to this. The SQL in question was UPDATE stats SET visits = (visits+1) And the question is, for the purpose of performance, does it matter if you lock all rows in stats in comparison to locking the table stats? Or, if the database uses a page-lock rather than a table/row lock? ...

details in one Row without any redundancy in the CATID

$query1 = "select * from linkat_link where emailuser = '$email2' or linkname ='$domain_name2' ORDER BY date desc LIMIT $From,$PageNO"; id   catid      discription            price ------------------------------------ 1         1     domain name     100 2   ...

SQL Server 2005 - Building a WHERE clause

Hello, I have a stored procedure that is dynamically building a query. The where clause associated with this query is based on filter values selected by a user. No matter what I do though, the where clause does not seem to get set. -- Dynamically build the WHERE clause based on the filters DECLARE @whereClause as nvarchar(1024) IF (@ha...

Beginner SQL question: querying gold and silver tag badges in Stack Exchange Data Explorer

I'm using the Stack Exchange Data Explorer to learn SQL, but I think the fundamentals of the question is applicable to other databases. I'm trying to query the Badges table, which according to Stexdex (that's what I'm going to call it from now on) has the following schema: Badges Id UserId Name Date This works well for badges like...

Complex query in mysql

I have two tables reports and holidays. reports: (username varchar(30),activity varchar(30),hours int(3),report_date date) holidays: (holiday_name varchar(30), holiday_date date) select * from reports gives +----------+-----------+---------+------------+ | username | activity | hours | date | +----------+-----------+----...

Check if access table exists

I want to log web site visits' IP, datetime, client and refferer data to access database but I'm planning to log every days log data in separate tables in example logs for 06.06.2010 will be logged in 2010_06_06 named table. When date is changed I'll create a table named 2010_06_07. But the problem is if this table is already created. A...

How to retrieve the ordered list of best articles having a minimum number of votes by using HQL ?

I have a Vote domain class from my grails application containing properties like article_id and note I want to HQL query the Vote domain class in order to retrieve the 5 best rated articles having at least 10 votes. I tried : SELECT v.article_id, avg(v.note), count(*) FROM vote v where count(*) >= 10 group by v.article_id order by av...

Foreign keys and pagination

This is my pagination script: <?php /*********************************** * PhpMyCoder Paginator * * Created By PhpMyCoder * * 2010 PhpMyCoder * * ------------------------------- * * You may use this code as long * * as this notice stays intact and * * the proper credit is given to * *...

Is there alternative way to write this query?

I have tables A, B, C, where A represents items which can have zero or more sub-items stored in C. B table only has 2 foreign keys to connect A and C. I have this sql query: select * from A where not exists (select * from B natural join C where B.id = A.id and C.value > 10); Which says: "Give me every item from table A where all sub-...

Database-independant SQL String Concatenation in Rails

I want to do a database-side string concatenation in a Rails query, and do it in database-independent way. SQL-92 specifies double-bar (||) as the concatenation operator. Unfortunately it looks like MS SQL Server doesn't support it; it uses + instead. I'm guessing that Rails' SQL grammar abstraction has solved the db-specific operator ...

SSIS package randomly hangs during execution

Hi Guys, I am having an ongoing and painful problem with an SSIS package. The package runs every 5 minutes as an SQL Agent Job and every 2-10 days the package will start running and never stop (thus preventing further executions). If I stop the hung job manually it will begin working perfectly again in the next 5 minute interval. The S...

Can I split up the values from one text field into multiple text fields?

I have a text field that stores a combination of three values, ':' delimited. (looks like A:B:C). I'd like to split those values into three actual columns in the table, but I'm not sure of the best way to go about doing this. I'm using sqlite3, any help super appreciated! ...

How can I count and group by between two date?

For example, the start date = '20100530' and the end date = '20100602' How can I write a SQL to display the below result? month: may, 2 days month: June, 2 days ...

Ensure in many-to-many relationship at least one relationship is primary

Sorry for the bad title, if you can think of a better one, let me know. Many-to-many relationship using tables. Product ProductCategory Category In the ProductCategory table i have boolean column primarycategory Each product must have a primary category. I want to find all products in my database which don't have a primarycategory...

How To Query Many-to-Many Table (one table's values becomes column headers)

Given this table structure, I want to flatten out the many-to-many relationships and make the values in the Name field of one table into column headers and the quantities from the same table into column values. The current idea which will work is to put the values into a Dictionary (hashtable) and represent this data in code but im wond...

Ampersand in sqlite query

How to construct sqlite query containing ampersand in filter: SELECT id FROM mediainfo WHERE album="Betty & Kate"; I use sqlite C interface (sqlite3_bind_text() and ? marks while query building) but neither C query nor SQLite Administrator return any data ...

Optimize "not in" query

Please help optimize this query: SELECT ts.SiteId, COUNT(ts.SiteId) AS Count FROM ts WHERE ts.SiteId not in (SELECT ts.SiteId FROM ts WHERE ts.uniqueid = 'xxx') GROUP BY ts.SiteId ORDER BY Count DESC ...

How to pass large number of parameters in stored procedure from code to MS SQL

Hello All: How to pass a large number of parameters (say 20+) to stored procedure from code. Like we can group all the parameters in one class object and then pass it across, but how to implement such this in case of stored procedures. Currently I have to create 20+ variables to pass parameters. Thanks Ashwani ...

RTF to TEXT in sql server

I have a RTF field in my SQL 2005 table, I need to convert it to Text and display it. After a quick research I got the following method... create function dbo.RTF2TXT(@in varchar(8000)) RETURNS varchar(8000) AS BEGIN DECLARE @object int DECLARE @hr int DECLARE @out varchar(8000) -- Create an object that points to the SQL Server EXE...