sql

What is wrong with this sql syntax?

Hai guys, I got the error Cannot call methods on nvarchar. when i executed the below sql query select User.[User_Id],User.[User_Name],User.Email_Id,User.Password,Role.Role_Id,Role.Role_Name,Role.Role_Description From [User] inner join [Role] on User.Role_Id=Role.Role_Id what is wrong in the above query? ...

When should one care about finishing one method before start next one?

Using C# in WPF, together with LINQ to SQL and LINQ for quering my generic collections, I noticed that sometimes, when I use several methods one after another and results of the first one are needed for next function, I should care about finishing actions of first function before starting next. SomeMethod() { FirstMethod(); NextMeth...

Is performing a count() calculation slowing down my mysql query?

I'm still learning about MySQL. I may be making a very basic error, and I'm prepared to be chastened here... What this query is trying to do is select the top members from our website based on a count of the number of book and recipe reviews they have made. I'm making a calculation of the total in the SQL query itself. The query is s...

LIKE Statement trouble

I am having some issues while using the TableAdapter and the LIKE Statement in VB 2008. I am wanting to search name using partial spellings. When I run the application nothing is returned. Here is my SQL: SELECT MEMBERS.RolodexID, MEMBERS.FirstName, MEMBERS.LastName, MEMBERS.address, MEMBERS.Address2, MEMBERS.City, MEMBERS....

How to index a table with a Type 2 slowly changing dimension for optimal performance

Suppose you have a table with a Type 2 slowly-changing dimension. Let's express this table as follows, with the following columns: * [Key] * [Value1] * ... * [ValueN] * [StartDate] * [ExpiryDate] In this example, let's suppose that [StartDate] is effectively the date in which the values for a given [Key] become known to the system. ...

SQL recursive CTE query error 'invalid column name - level'

Trying to write a recursive CTE query, keep getting the following error: level, invalid column name This is the query, where am I going wrong? WITH OwnerHierarchy AS ( SELECT PairID, ChildID, ParentID, 0 AS level FROM BusinessHierarchy UNION ALL SELECT e.PairID, e.ChildID, ...

Linq2Sql Updates

Wondering if anyone else has done most of their Update SQL using stored procedures over Linq2Sql? I like Linq2Sql for all the other operations but Updates seem to be nasty. The generated SQL doesn't look good in profiler with all the columns in the Where clause, then you have to select the current object to set the fields from the edited...

SQL Server Cast and Rounding

I have in my select clause: AVG (cast(scale as decimal(5,2))) I keep getting a number like: 0.6523412897, nothing I do seems to get me to my desired: 0.65. Basically I want to have a scale of 2 (two decimal places). Thanks ...

write the hibernate query to retrieve data with latest timestamp.

I want to retrieve unique data froma table based on latest time stamp. So If I have a table like this guid 6 1/7/2010 9:55:29 PM guid 6 1/5/2010 2:59:29 PM guid 6 1/7/2010 2:55:29 PM I need to write a query where I can query with no 6 and with latest timestamp in the same table. So it should return me : guid 6 1/7/2010 ...

NHibernate and database changes/deployment

I'm looking into using NHibernate and Fluent NHibernate for my next project but one thing I'd like clearing up before hand is how do you manage changes to the database? eg, I have NH + FNH working, application has been deployed and is live but we make a change in the development environment, for example say we add a new property to a en...

SQL selection over two rows

How do I select in a table like below all objects that have a-A and b-B (as key-value pair)? Something like: SELECT DISTINCT(OBJECT) FROM MYTABLE WHERE key = 'a' AND value = 'A' AND key = 'b' AND value = 'B' ...where the result would be 1 and 3. I know that this SQL statement doesn't work, but I hope it explains a b...

INSERT IGNORE Inserting 0 rows

Hi Everyone: When I am attempting to run "INSERT IGNORE ..." in MYSQL to add only one variable to a table of several options, after the first insert, it refuses to work. It says "Inserted rows: 0" and doesn't insert my new value into the database. I believe this is because there is already an entry with a "nothing" value and MYSQL doe...

PHP SQL Server Database Select

I have three SQL Server databases on one SQL Server instance. Every time I do query to different databases, I have to select the database. Is there a way to do query without database select. Like this: SELECT * FROM database_name.table_name WHERE id = 1 ...

sql like operator to get the numbers only

This is I think a simple problem but not getting the solution yet. I would like to get the valid numbers only from a column as explained here. Lets say we have a varchar column with following values ABC Italy Apple 234.62 2:234:43:22 France 6435.23 2 Lions Here the problem is to select numbers only select * from tbl where answer li...

[PostgreSQL] Creating view from complicated select

Hi, I have quite complicated query from which I would like to create a view. The query looks like this: select s.avg as c3, fs.bayes, fs.sure, fs.visu, fs.fstd from ( SELECT AVG(q.c3), COUNT(q.c3), q.std FROM ( SELECT std, c3, ROW_NUMBER() OVER (PARTITION BY std ORDER BY id) AS rn FROM ssims WHERE obr...

Decimal number, to_char, and Oracle

Hello, I am trying to figure out a format spec of to_char() that would give me the following result. to_char(0.1, '[FORMAT_SPEC]') gives 0.1 and: to_char(1, '[FORMAT_SPEC]') gives 1. I've tried the following solutions: to_char(0.1) gives '.1'. to_char(0.1, 'FM0.099') gives 0.1, which is okay, however: to_char(1, 'FM0.099')...

When CouchDB Failed?

I keep seeing references to the idea that "CouchDB may not be the best tool in every situation." This is good to know, but unfortunately also applies to every technology. What would be much more helpful is a description of how CouchDB was tried on a project and subsequently abandoned for a traditional SQL database. If you've tried Couc...

SQL Query to find earliest date dependent on column value changing

I have a problem where I need to get the earliest date value from a table grouped by a column, but sequentially grouped. Here is a sample table: if object_id('tempdb..#tmp') is NOT null DROP TABLE #tmp CREATE TABLE #tmp ( UserID BIGINT NOT NULL, JobCodeID BIGINT NOT NULL, LastEffectiveDate ...

text in tables?

Hello, I like to organize a lot of information from literature reviews in "tables" (information not unlike product comparisons, but for scientific research), but often the information I enter can contain lines or paragraphs of text and becomes unwieldy in a spreadsheet. I've heard SQL relational tables are often used for this purpose; fo...

TSQL: union results from two selects (procedures?)

I have two procedures - two huge sets of selects with several sub-select and unions. I need to union results from these procedures and I still need them to exists separately. Something like that: if @Param = 1 Then PROCEDURE1 if @Param = 2 THEN PROCEDURE2 if @Param = 3 Then PROCEDURE1 union PROCEDURE2 I read that it's i...