sql

Looping through a datatable and remove row

I have populated a Datatable, from 2 different servers. I am able to make adjustments where my length>0, what I want to do is remove the rows that does not hit. Here is a summary of what I have DataRow[] dr = payments.dtPayments.Select(myselect); if (dr.Length > 0) { for (int a = 0; a < dr.Length; a++) { if (thisOption ==...

How can I hide duplicate records (within a crystal report) which have already been reversed?

This question is a follow-up to a question I asked the other day ("Need to find duplicate records but exclude reversed transactions"). I have a Crystal Report which displays customers' fuel transactions. There are occasions when a duplicate transaction will be imported erroneously. If/when this error is discovered, the admin will reve...

SQL join to find inconsistencies between two data sources

I have a SQL challenge that is wracking my brain. I am trying to reconcile two reports for licenses of an application. The first report is an access database table. It has been created and maintained by hand by my predecessors. Whenever they installed or uninstalled the application they would manually update the table, more or less....

Tricks for generating SQL statements in Excel

Do you have any tricks for generating SQL statements, mainly INSERTs, in Excel for various data import scenarios? I'm really getting tired of writing formulas with like ="INSERT INTO Table (ID, Name) VALUES (" & C2 & ", '" & D2 & "')" ...

Help with writing a SQL query for Nested Sets

I'm storing a tree in a DB using nested sets. The table's fields are id, lft, rgt, and name. Given a node ID, I need to find all of its direct children(not grandchildren) that are themselves leaf nodes. ...

Can SQL Server Express be used to effectively administrate a SQL Server Standard/Enterprise installation?

We have a number of MS SQL Server 2005 installations (both Standard and Enterprise editions) on our webservers. From time to time I need to administrate them from home. Right now I'm using Remote Desktop to connect to my work machine, but I'd prefer to install SQL Server Management Studio on my home machine so that I can work more effici...

MySQL code fails to display category name (WordPress database)

Why does this code fail to display the category name "Apples" using the current WordPress taxonomy system? The Category names are stored in the $wpdb->terms table (wp_terms). <?php $ra_category_id = 3; $ra_category = $wpdb->get_results("SELECT name FROM $wpdb->terms WHERE term_id = '3'"); $ra_category_name = $ra_category->name; ?...

rename schema in SQL server 2005

How can I rename a schema in SQL Server 2005? ...

how can i write a sql query that finds rows where one column is a substring of another column

I wish to find all rows in a table where one column is a substring of another column. In other words, suppose I have a table (called people) with two columns: firstname and lastname, and I want to find all people like "rob robinowitz" and "jill bajillion". Is there a way to do something like "select * from people where lastname like %f...

Is it possible to use CONTAINSTABLE to search for "word1" in column1 AND "word2" in column2

We used to have a search, that checks two columns for some words. Both columns must contain some words provided, so we use AND ... no doubts FULLTEXT INDEX is used on the columns. The select is more or less like this: SELECT * FROM SomeTable WHERE (CONTAINS(Column1, 'word1 OR word2') AND CONTAINS(Column2, 'word3 OR word4')) now ...

Optimize Group By in LINQ to Entities

I have this query in LINQ to Entities. var query = (from s in db.ForumStatsSet where s.LogDate >= date1 && s.LogDate <= date2 group s by new { s.Topic.topicID, s.Topic.subject, s.Topic.Forum.forumName, s.Topic.datum, s.Topic.Forum.ForumGroup.name, s.Topic.Forum.forumID } into g ...

Optimized SQL for tree structures

How would you get tree-structured data from a database with the best performance? For example, say you have a folder-hierarchy in a database. Where the folder-database-row has ID, Name and ParentID columns. Would you use a special algorithm to get all the data at once, minimizing the amount of database-calls and process it in code? Or ...

Oracle - Select where field has lowercase characters

Hello, I have a table, users, in an Oracle 9.2.0.6 database. Two of the fields are varchar - last_name and first_name. When rows are inserted into this table, the first name and last name fields are supposed to be in all upper case, but somehow some values in these two fields are mixed case. I want to run a query that will show me al...

How to do a WHERE...IN... clause in LinqToSql?

Bear with me, I'm beginning: How can I select multiple elements using a WHERE...IN... type of clause as in select * from orders where orderid in (1, 4, 5) in LinqToSql? I'd prefer not to have a lambda expression since they scare me. Thanks in advance! ...

Is a dynamic sql stored procedure a bad thing for lots of records?

Hello, I have a table with almost 800,000 records and I am currently using dynamic sql to generate the query on the back end. The front end is a search page which takes about 20 parameters and depending on if a parameter was chosen, it adds an " AND ..." to the base query. I'm curious as to if dynamic sql is the right way to go ( does...

update with changing set value

How can we write an update sql statement that would update records and the 'set' value changes every time. For example: If we have records like this SomeNumber SomeV CurCode WhatCodeShouldBe 200802754 432 B08 B09 200802754 432 B08 B09 200802754 432 B08 B09 200808388 714 64B C00 200804119 270 64B C00 I wish to update each 'SomeNumber' ...

Ambiguous column name error

When executing the following (complete) SQL query on Microsoft SQL Server 2000: SELECT B.ARTIFACTTNS, B.ARTIFACTNAME, B.ARTIFACTTYPE, B.INITIALBYTES, B.TIMESTAMP1, B.FILENAME, B.BACKINGCLASS, B.CHARENCODING, B.APPNAME, B.COMPONENTTNS, B.COMPONENTNAME, B.SCAMODULENAME, B.SCACOMPONENTNAME FROM (SELECT DISTINCT A.ARTIFACTTYPE, A.A...

SQL Conditional Order By

I am doing a join on two tables. One is a user's table, and the other a list of premium users. I need to have the premium members show up first in my query. However, just because they are in the premium user table doesn't mean they are still a premium member - there is an IsActive field that also needs to be checked. So basically I need...

SQL Server - update one table with first and last rows from another table.

I have a couple of tables which are used to log user activity for an application. The tables looks something like this (pseudo code from memory, may not be syntactically correct): create table activity ( sessionid uniqueidentifier not null, created smalldatetime not null default getutcdate() ); create table activity_details ( ses...

How do you identify the triggers associated with a table in a sybase database?

I am using SQL Advantage and need to know what the SQL is to identify the triggers associated with a table. I don't have the option to use another tool so the good old fashioned SQL solution is the ideal answer. ...