sql

Database naming conventions

I'm starting a new project and want to begin with a database naming convention that won't become a hindrance in the future. I want a consistent convention for tables and columns. At a previous employer I have seen all objects in upper case with underscores separating words. e.g. CREATE TABLE USER_TYPES (USER_TYPE_ID INT); Is this t...

SQL Query for Disabled Active Directory Accounts

I need to query AD to determine if a users account is disabled. Using a similar query used in the answers here SELECT * FROM OPENQUERY(ADSI, 'SELECT sAMAccountName FROM ''LDAP://DC=MyDC,DC=com,DC=uk'' WHERE objectCategory = ''Person'' AND objectClass = ''user'') I believe to determine if an account is disabled I have to use the user...

Oracle SQL use Coalesce

I have this query that works in Oracle but I want to convert it to use Coalesce because of some problems I'm having with Visual Studio. SELECT * FROM a Left Join b on b.institution_code=a.institution_code WHERE (upper(a.Login_Name)=UPPER('%' || :Login_Name || '%') OR :Login_Name IS NULL) AND (upper(a.Display_Name) Like UPPER(...

Unique Application Key

I am creating a web service to allow application developers (my fiends LOL) to query my database. The thing is, as a security constraint i wanna be able to track each user. I am in the process of creating a unique app id like facebook or Google maps. Any help? The developer must submit a user-name and email-address, when they click gene...

Copy data between tables in different databases without PK's ( like synchronizing )

I have a table ( A ) in a database that doesn't have PK's it has about 300 k records. I have a subset copy ( B ) of that table in other database, this has only 50k and contains a backup for a given time range ( july data ). I want to copy from the table B the missing records into table A without duplicating existing records of course...

Creating a CHANGE script in sql server management studio?

Hi there, i was wondering if there is a way to automatically append to a script file all the changes i am making to my columns, tables, relationships etc... The thing is i am doing a lot of different changes on a TEST db and the idea will be to apply this change script when i move the test db to production .. hence keeping production d...

Is There a good ASP.NET membership provider for Postgre SQL

I have decided to use postgre instead of sql server. My only problem is that I need a Membership provider for postgre. Are there any good ones out there? ...

SQL Server Foreign key/Insert issue

I created two database tables. SQL Server will not allow me to insert items into my second table, the one with the foreign key. The error I keep getting is Msg 207, Level 16, State 1, Line 53 Invalid column name 'ExemNonExemStat'. Following is my code. Please help, this is driving me crazy. ----Create Job Title Table CREATE TAB...

Using Columns in a RegExp in MySQL

I'm using the following query with regexp: SELECT a.id, a.company, a.name, b.title, b.description, b.t_id FROM a, b WHERE ( b.title REGEXP "[[:<:]]a.company[[:>:]]" OR b.description REGEXP "[[:<:]]a.company[[:>:]]" OR b.title REGEXP "[[:<:]]a.name[[:>:]]" OR b.description REGEXP "[[:<:]]a.name[[:>:]]" ) AND a.company != '' AND a.name ...

SQL Find Possible Duplicates

Hi I need SQL code that will identify possible duplicates in a table. Lets say my table has 4 columns: ID (primary key) Date1 Date2 GroupID (Date1, Date2, GroupID) form a unique key. This table gets populated with blocks of data at a time, and it often happens that a new block is loaded in that contains a number of records that are...

Populate text boxes from SQL database

Hi all... I have seven fields that need to be populated in seven text boxes. The data is coming from a SQL Compact DB... Here's my code so far, but I'm stuck. What do I need to do to populate the text boxes on Form Load... thanks much. Woody private void mcContactSubmit_Load(object sender, EventArgs e) { // Setup our SQL connect...

Without stored procedures, how do you page result sets in ASP.NET?

Without stored procedures, how do you page result sets retrieved from SQL Server in ASP.NET? ...

Difference between different types of SQL?

What are the differences between all of the different tpye of SQL? i hear of PostgreSQL, SQLite, MySQL, SQL, .... What are the differences between them? ...

best mysql approach?

I'm writing an application that displays posts, much like a simple forum system. Posts can be marked as urgent by users when they submit the post, but a moderator must approve the "urgent" status. A post will still be displayed even if it has not been approved as urgent, but will just appear to be a normal post until the moderator approv...

SQL SELECT DISTINCT ID from copies ORDER BY CID

Hi everyone, i want something like this: SELECT DISTINCT ID from copies WHERE timestamp < 1229444506 ORDER BY CID the problem is that this one only return ID and i need CID and other columns in the table. It may be that this is totally wrong for other reason aswell, so i will explain what i need. I have a table that "record" every r...

please let me know the issue with following sql query

SELECT pd_end_dt,nrx_cnt FROM wkly_lnd.lnd_wkly_plan_rx_summary WHERE pd_end_dt >TO_DATE('01/01/2009') It is giving error ORA-01843: not a valid month i ran the following it did fine SELECT pd_end_dt,nrx_cnt FROM wkly_lnd.lnd_wkly_plan_rx_summary WHERE pd_end_dt > '01-Jan-09' but if i want to have week wise data how to do dat ...

Update only Time in a mysql DateTime field

How can I update only the time in an already existing DateTime field in MySQL? I want the date to stay the same. ...

a sql query to compare results of follwing queries

SELECT pd_end_dt,SUM(nrx_cnt) Total_Count FROM wkly_lnd.lnd_wkly_plan_rx_summary WHERE pd_end_dt >= '01-Sep-08' AND pd_end_dt < '30-Sep-08' GROUP BY pd_end_dt SELECT pd_end_dt,SUM(nrx_cnt) Total_Count FROM wkly_lnd.lnd_wkly_plan_rx_summary WHERE pd_end_dt >= '01-Sep-07' AND pd_end_dt < '30-Sep-07' GROUP BY pd_end_dt the result set on ...

Speeding up temp table joins in SQL Server

I have 2 temp tables #temp1 and #temp. Both have a key and date columns. Both have around 25k rows. And I'm left joining them on the basis of the key and date which are unique on all rows. It's taking around 4 minutes for this join to complete. Is there any way to speed it up or any alternative methods? ...

Single or multiple INSERTs based on values SELECTed

We're extracting booking information for our tennis courts from our SQL database into a simple results table to help us build a picture of court usage. It's pretty straight-forward except when it comes to bookings that last more than an hour. At present, each booking results in a row in our results table. Each row contains a start-time,...