sql

Sql query on rownum

SELECT instmax FROM (SELECT instmax ,rownum r FROM ( SELECT instmax FROM pswlinstmax ORDER BY instmax DESC NULLS LAST ) WHERE r = 2 ); After execution it's giving this error: ORA-00904: "R": invalid identifier 00904. 00000 - "%s: invalid identifier" *Cause: *Action: Error at Line: 39 Column: 8 why it's giving th...

What is wrong with this SQL query?

This is the SQL query I wrote in MS Access 07: IF EXISTS (Select * FROM MyTable) print 'Yes' else print 'No' This is the error it's giving me when i run the query: "Invalid SQL Statemenet; Expected DELETE, INSERT, PROCEDURE, SELECT, UPDATE" The query is correct, as far as I know, I think it's from Access, can anyone help me plea...

why both the sql query on rownum are giving different result

>SELECT instmax FROM (SELECT instmax, rownum r FROM ( SELECT * FROM pswlinstmax ORDER BY instmax DESC NULLS LAST ) ) WHERE r = 2; INSTMAX ------- 1049 >SELECT instmax FROM (SELECT instmax, rownum FROM (SELECT * FROM pswlinstmax ORDER BY instmax DESC ) ) WHERE...

How to drop some characters with Regex in vs ?

I have a sql table and I have a column which includes data such as: B757-34-11-00-I-1, A300-223100-0503-1 etc. A300-223100-0503-1 -> 223100-0503-1 B757-34-11-00-I-1 -> 34-11-00-I-1 How can i do that with regex? I need two kinds of solutions: sql and C#. how can I do that with sql query in SQL and C# i need drop charater as far...

Expain the result of "explain" query in mysql

I am using indexing for mysql tables. My query was like this EXPLAIN SELECT * FROM `logs` WHERE userId =288 AND dateTime BETWEEN '2010-08-01' AND '2010-08-27' I have indexing on field userId for this table logs, and the result of explain query is like below. id select_type table type possible_keys key key_len r...

Using delimiters to split column in T-SQL while skipping delimiters

OK the question title is vague, but here's the problem. I have a list of filenames in the first column of a table called Files that I want to parse data from that are underscore delimited, however sometimes I want to skip the underscore. Every filename is in the form of: distance1000_7_13_2010_1_13PM_AveryDennisonAD_2300008_10S_Lock.csv...

why there's a difference of performance gain among both these queries?

SELECT instmax, r FROM (SELECT instmax, rownum r FROM ( SELECT instmax FROM pswlinstmax ORDER BY instmax DESC NULLS LAST ) WHERE rownum <= 10 ) WHERE r >=6; Output SELECT instmax, r FROM (SELECT instmax, rownum r FROM ( SELECT instmax FROM psw...

SQL Server Select on Different column

Hi All, I want to select a value based on different column in SQL Server, say Result = Isnull(A.OUT1,'')<>'' then select A.OUT1 Isnull(A.OUT2,'')<>'' then select A.OUT2 Isnull(A.OUT3,'')<>'' then select A.OUT3 How to form query to get the Result? ...

SQL 2005 - Search String

I want to write a stored procedure that will accept a parameter of @searchString. This will be a varchar(100) and will contain a query value. How can I write the sp so that it could do something like: SELECT * FROM Application a INNER JOIN Applicant app ON app.ApplicationId = a.ApplicationId WHERE a.ApplicationId = @searchString OR app....

Returning first instance of value across multiple tables (and returning associated columns)

I am looking to return the following information for each contact contained within a set of tables: Contact_id | first_Event_date | first_Event_id | event_type id123456 | 01/12/2007 | eveid123456 | table1 id456455 | 05/06/1999 | eveid456585 | table4 Where the data reflect...

Oracle Variable substitute - Synonym

I want to substitute a variable in oracle. The var is coming in via SQLPlus and is reference using &1 &1 in my scenario is the schema name - here's the SQL. CREATE SYNONYM ACCOUNT FOR &1.ACCOUNT; Assuming &1 equals ABC the synonym created is for ABCAccount, instead of ABC.Account. For some reason the period is removed. Any ideas w...

C# / Execute Parameterized SQL StoredProcedure via ODBC

Hello, from within a C# WinForms-App I must execute a parameterized Stored Procedure on a MS SQL Express Server. The Database Connection works, the Procedure works either, but I get an Error Message: 42000: Missing Parameter '@KundenEmail' although I'm sure I added the parameter correctly. Maybe some of you could have a look - I ...

SQL : return value in required format

select myvalue from mytable where id=1; it return a value of 10 digits(Ex: 1234567890). I want these value in 1234.56.7890 format as return value. means myvalue can return value in required format and not in stored format. Can anyone help me. You ideas are very wellcome ...

sql query multiple record insertion

how can i insert multiple records using single sql statement ...

Cascade Delete Query

I have three tables. Product, Company, Employee ProductId of Product table is foregin key for Company and CompanyId of Company table is foregin key for Employee So on deleting ProductId from Product table, all the related records in other tables should delete. But I can't touch schema(can't use alter table). How should I write the que...

login failed for user 'sa'. The user is not associated with a trusted SQL Server connection. (Microsoft SQL Server, Error: 18452) in sql 2008

Hi so make quick: i use windows 7 ultimate. I can login with windows authentication mode but sql authentication with user 'sa' don't work!. sa user is enable so what do i do? ...

How to Add a Third Table in an SQL Query Containing a SUM

I have the following SQL Query: SELECT porel.refcode, podetail.ponum, SUM(podetail.orderqty * podetail.unitcost) AS Total FROM podetail LEFT JOIN porel ON podetail.ponum = porel.ponum WHERE porel.poline=podetail.poline AND porel.reftype = 'SPEX' GROUP BY porel.refcode, podetail.ponum ORDER BY porel.refcode, podetail.ponum which works ...

PK constraint violated with INSERT/UPDATE

Hello, i have a Dimension Table like this : my_Table pk1 Primary key pk2 Primary key pk3 Primary key col1 col2 col3 ... and using a procedure to fill this table with the MERGE INTO statement : MERGE INTO my_Table dest USING ( SELECT <columns> FROM <tables> WHERE <conditions> ) src ON (dest.pk1 = src....

SQL: return string describing user category based on a field

The idea is to get in the result a new column describing the user "category". This category could for example be "under18","normal","over65" based on user age. That is, for each user in my table I want to get as result its ID and this description in a column called "category". How would you proceed? I need this because the data will la...

Creating entities from stored procedures which have dynamic sql

I have a stored procedure which uses a couple of tables and creates a cross-tab result set. For creating the cross-tab result set I am using CASE statements which are dynamically generated on basis of records in a table. Is it possible to generate an entity from this SP using ADO.NET Entity framework? Cuz each time I try Get Column Info...