sql

how to setup datepart set sql start date and end date

i had a problem how to set up the datepart exact date that i want: hers my example Code: SET DATEFIRST 7; select CAST(DATEPART(wk, '01/03/2010') AS CHAR(4)).. // 01/01/2010 to 01/03/2010 to return 1 how can i set the datepart if 01/03/2010 to 01/09/2010 returns = 1 and 01/10/2010 to 01/16/2010 returns to 2.. up to 53 weeks.. ...

How to convert this dynamic sql script into LinqToSql?

How to convert this dynamic sql script into LinqToSql? -- Create sample table Create Table TEST (DATES Varchar(6), EMPNO Varchar(5), STYPE Varchar(1), AMOUNT Int) -- Insert sample data Insert TEST Select '200605', '02436', 'A', 5 Union All Select '200605', '02436', 'B', 3 Union All Select '200605', '02436'...

In MySQL, how to write an INSERT-INTO-VALUES query so that it to be silently discarded if a record with same primary key value already exists?

I have to import a large set of records which can contain duplicates. The table is a MyISAM table with a composite primary key and no foreign keys. How do I specify that if a primary key values combination of a record being inserted already exists in the table, it will just discard the particular insert without throwing an error or inser...

Table Conversion- Oracle

I have a table with this structure: date colname value ---------------------------- date col1name col1's value date col2name col2's value date col3name col3's value Now I need to convert it into this structure: date col1name col2name col3name ----------------------------------------------- date col1's ...

cursor in forms 6i

I am working on form6i and using case expression in cursor.But the following code is not compiling Is Forms 6i not support the case expression in cursor or any method to write case expression in forms ...

Using Encrypt=yes in a Sql Server connection string -> "provider: SSL Provider, error: 0 - The certificate's CN name does not match the passed value."

Hi geniuses (is that genii?) I'm using 'Encrypt=yes' in a Sql Server connection string, because i need the tcpip traffic to be encrypted, but on opening the connection i get the error: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 ...

How to query on a column of datatype long storing datetime values?

I am working on a table which has a column called ccDate of type long which stores the date values in long format - for example 20021218. Actually it is a datetime value for 2002-12-18 (yyyy-MM-DD). Now i want to query records from this table comparing this datetime values. for example get all records where ccDate < todays's date. How c...

Deploy sample data along with main setup of app

Hi, We need to deploy some sample data along with the application. The idea is after the deployement of application, and setting up the database. there should be some sample data available to users .This data is around 30-40 rows in 4 tables. What should be the best approach to achieve this. 1. Insert SQL scripts 2. Export data to file...

How to execute a SQL script to prepare DB before executing Unit Tests in Visual Studio

Hello, I have a lot of unit test that depend on a certain configuration of a database. I would like to execute a script every time I run the unit tests so the database is Ok and the tests do not fail due to wrong data at DB. I currently have a SQL script to put the right data at the DB. Is there a way of doing that from Visual Studio (...

Converting a serial number into date

Hallo friends, In an Excel sheet I will receive the data, which in turn I need to upload it to sql server and then implement the logic. I have received a date field --[Due Date] as number ex:-.40317. In Excel if you right click it and then format it to a date. It will show the correct date as 19.05.2010. So after uploading the file a...

Filteration in where clause: syntax error?

Please help me to sort this query: WHERE RECEIPT_DATE BETWEEN( Coalesce(@FROM_DATE,RECEIPT_DATE) AND Coalesce(@TO_DATE,RECEIPT_DATE) ) AND OFFICE_ID=Coalesce(@OFFICE_ID,OFFICE_ID) Error: Incorrect syntax near the keyword 'AND'. ...

Does Linq to Entities throw SqlExceptions?

Hi! I'm using linq to entities, and my entity model is sitting on top of MSSQL database. I'm wondering if linq to entities throws SqlExceptions or not. In other words, will the below code catch exception successfully if there was a problem connecting to the database? If it doesn't, what's the best way to handle exceptions when using lin...

Relation between sql query and unix process

I have a procedure that gives below output. SID is 155 SERIAL# is 5466 PROCESS is 1323 SQL_HASH_VALUE is 2701082490 TIME_REM_MIN is 3 TIME_START is 09-07-08 15:38:10 TIME_ELP_MIN is 2 And a unix 'ps' command that would give output as below. $ ps -e -o pcpu -o pid -o user -o args |sort -r -k 1 |head -30 %CPU PID USER...

Sqlite 3: How to DROP TABLE IF EXISTS?

My version of sqlite does not support IF EXISTS operator. So how can I drop a table which may or may not exist without getting an error slapped at me? EDIT: FYI, IF EXISTS and IF NOT EXISTS were added to SQLite 3.3.0 http://www.sqlite.org/releaselog/3_3_0.html. That's not my solution though, I can't update the version on a live applica...

sqlite filtering by sum

I have a database with 1000 records containing a file name and a file size on each row. If the SUM of all file sizes exceeds a specific limit, then: - I need to create a sql query to delete all the remaining rows, from oldest to newest Any suggestions? Thanks ...

sql update records with incrementing value starting from 1 each time

I am adding batches of records to a table using a single insert statement. I want each new batch to be allocated incrementing numbers, but starting from 1 each time. So, if I have Batch Name IncementingValue 1 Joe 1 1 Pete 2 1 Andy 3 2 Sue 1 2 Mike 2 2 Steve 3 and I ...

Programmatic SQL Beautifier or Reformatter for C#

I'm looking for a beautifier or reformatter for SQL that is written in C# in order to programmatically beautify my SQL output. It does not need to have colouring, but indention and line breaks would be very nice. Does anyone know of such a component ? ...

Can anyone help me write a sql query...

jkdfhdjfhjh&name=ijkjkjkjkjkjk&id=kdjkjkjkjkjkjjjd&class=kdfjjfjdhfjhf The above string has some characters starting with & and ending with = for example we have &name= and I just need this from the above string. similarly I need &id=, &class= I need the output under a single column. Final Extract ---------------------- &id=, &class...

Skipping rows in sql query (finding end date based on start date and worked days)

Given these two (simplified) tables: Task (list of tasks/employee with their start date and estimated cost) --------- TaskId: int EmpId: int Start: Date Days: int WorkableDays (list of working dates/employee - i.e., without weekends/holidays) --------- EmpId: int Day: Date Is there any way to get this result using just Access SQL (o...

Why does column alias not work in doctrine?

My script is like this: $query = Doctrine_Query::create () ->select('count(p.product_id) as num_a') ->from ( 'ProductComments p' ) ->groupBy('p.product_id') ->having('num_a =2 '); And the generated sql is: SELECT COUNT(i.product_id) AS i__0 FROM productcomments i GROUP BY i.product_id HAVING num_a=2 Thus I get...