sql

SQL Question - Please help

Hi All, i am working on something like, i have two tables Table : 1, Name : NdcAwp, Columns-Ndc, AwpUnitCost Table : 2, Name : InvalidNdcs, Column-Ndc Now, i wanna delete those records from Table : 1 whose AwpUnitCost is <= 0, AwpUnitCost IS NULL and it doesnt have the same Ndc from Table : 2. Thanks Nick ...

mysql/sql server: SELECT @@identity

is there a difference in the way this functions between the two databases mysql and sql server: SELECT @@identity ...

Fundamental SQL Knowledge?

I'm about to take a challenge test so I don't have to take a Database Processing class. Even though I've worked with databases through out the last 5 years, I can't help but be nervous about the test. It's 50 questions and there's 2 parts: a true/false part and a part where I actually write SQL commands. It's non-platform specific. What...

Condition in sql query

Hi I want to insert in sql query something like that: Select * from Users where id=[if @userId>3 then @userId else "donnt use this condition"] and Name=[switch @userId case 1:"Alex" case 2:"John" default:"donnt use this condition"]; How can i do it? yet another similar question When showAll is false it works ok but when showAll i...

HOW do i use SELECT @@identity in sql server?

i am currently calling SELECT @@identity from VBA in mysql: Set rs = cn.Execute("SELECT @@identity", , adCmdText) but since i am going to be working with sql server db instead of mysql, i would like to know how to make this statement sql-server friendly would it just be Set rs = cn.Execute("SCOPE_IDENTITY()", , adCmdText) ?? ...

SQL - Best way to GroupByDay from 6AM to 6AM

I need to query a large number of rows (containing a timestamp column) and aggregate the results by day. The trick is I need the aggregate functions to be grouped for each day from 6AM until next day at 6AM, not from midnight to midnight. Obviously, I can do some sort of "group by DATEPART(day,Timestamp-6 hours)" but for millions of row...

PostgreSQL indices- are these redundant?

CREATE INDEX alias_pub_idx2 ON info.palias USING btree (publisher_id, player_id, pub_player_id); CREATE INDEX alias_pub_idx3 ON info.palias USING btree (player_id); The first includes the three columns; the latter includes only the one. I'm thinking they are redundant- that the first btree index is sufficient, but I'm not ...

getting all chars before space in SQL SERVER

i am trying to get all chars before the space: SUBSTRING(reporttime,1,CHARINDEX(reporttime,' ',1)) but it is not working. please help! example data: 7/8/2010 11:47 AM 7/8/2010 10:55 AM ...

why does SELECT SCOPE_IDENTITY() return null?

in what case does SELECT SCOPE_IDENTITY() return null? i am doing this: Set rs = cn.Execute("SELECT SCOPE_IDENTITY()", , adCmdText) capture_id = rs.Fields(0) and i getting capture_id=null ...

show create table tablename (how do i do this in sql server) ?

in mysql it is possible to do show create table tablename what is the sql server equivalent? ...

Oracle SQL query count group by timestamp substring

Given a table that has a column of string "timestamps" (yyyyMMddHHmmssSSS format), I want to substring the first 8 characters, and get a count of how many rows have that substring, grouping the results. Sample data... TIMESTAMP 20100802123456123 20100803123456123 20100803123456123 20100803123456123 20100804123456123 20100805123456123 2...

Select top statement ordering by non-unique column

I have two sql queries select * from table1 ORDER BY column1 Select top 10 * from table1 ORDER by column1 Column1 is a non unique column and table1 does not have a primary key. When I run both queries, I'm getting the rows returning in different orders. I attribute this to the fact that the criterion for ranking (the Order By) is no...

Optimal query writing

I have 3 tables t1,t2,t3 each having 35K records. select t1.col1,t2.col2,t3.col3 from table1 t1,table2 t2,table3 t3 where t1.col1 = t2.col1 and t1.col1 = 100 and t3.col3 = t2.col3 and t3.col4 = 101 and t1.col2 = 102; It takes more time to return the result (15 secs). I have proper indexes. What is the optimal way o...

sql cleanup function. rows doesnt get really deleted

hi there, i am using java sqlite (org.sqlite.JDBC) with this i am adding a new row of data to the table, one field is supposed to take up a big amount of base64 encoded data (like pdf) the type of this field is sql-TEXT. now, if i delete the row with "DELETE FROM table WHERE id='id'" the row gets deleted as expected, my sqlite browser c...

PostgreSQL table design -- how to avoid reusing IDs

I'm designing an app with a rather complex table design using the Postgres database, and am stuck on one point that I was hoping someone could offer advice about. I have several tables, each of which has a feature id (or fid). Different types of entities have different attribute schemas, so I have to create a different table for each t...

merge tables from two backup files - SQL Server

Hi, I have two .bak files These files contain different tables in them, and it is guaranteed that indexing is consistent across both files I can easily restore database A from A.bak and have tables a1, a2, a3 and likewise table B from B.bak with tables b1, b2, b3 What I really want is to restore database AB from both A.bak and B.bak ...

Invalid Syntax Near ',' - SQL C# Error

I keep getting the following error: (C# WinForms) "Invalid syntax near ','" I have the following code: // Initialize and instantiate a new reader object. SqlDataReader slrr = null; // Send command. System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("SELECT ActivationCode FROM CAccounts ...

MySQL Which version one to use?

I have asked how to DBSM and would like to proceed knowing more about MySQL. When I log into their website, I dont know which one to try. There are Community Server, Cluster, Workbench and Connector. Please guide. Note: I am working on excel database (which I found out on this website that it is not a good way to do it) with size o...

Invalid object name "CAccounts".

I keep getting this error: Invalid object name "CAccounts". and the code I have is: System.Threading.Thread thread = new System.Threading.Thread(() => { // Set ConnectionString. String sConSg = "CONNSTRING HERE"; using (SqlConnection connection = new SqlConnection(sConSg)) { try { c...

I am unable to sort data in ascending order using ORDER BY ASC

The query I am running is select accountid from general order by accountid ASC The result I get is accountid ------------ 1 1001 1002 10021 10026 1006 1007 Why is it not ordering correctly? It's a simple query and I am completely lost at how I can resolve this matter. ...