sql

How can I change column length using HQL query?

I tried session.createSQLQuery("ALTER TABLE People MODIFY address VARCHAR(1000);").executeUpdate(); but this throws org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query After a lot of googling, the recommendation is to use HQL instead of SQL query to do bulk updates. Not sure how to use HQL to a...

Max (SQL-Server)

Hello everyone. I have a table that looks like this: BARCODE | PRICE | STARTDATE 007023819815 | 159000 | 2008-11-17 00:00:00.000 007023819815 | 319000 | 2009-02-01 00:00:00.000 How can I select so I can get the result like this: BARCODE | PRICE | STARTDATE 007023819815 | 319000 | 2009-02-01 00:00:00.000 select by using...

How to get numeric random uniqueid in SQL Server

I am using SQL Server 2005, please tell me how can I get 6 digits (unique numeric which should be random) value for every row in table. I have a field in table in which I need 6 digit numeric value (random and unique). Please help me to do this. ...

SQL to generate a list of numbers from 1 to 100

Using the DUAL table, how can I get a list of numbers from 1 to 100? ...

Select a column returned by a stored procedure

I have a stored procedure which is returning me about 50 columns. I want to write a query, where I will be able to select a particular column from the list of column returned by the SP. I tried writing select RSA_ID from exec(uspRisksEditSelect '1') But Its throwing me an error. I think we need to write some dynamic sql for it. But I am...

Right way to implement a n-to-m relation

Hello, this is a part from my database structure: Table: Item Columns: ItemID, Title, Content, Price Table: Tag Columns: TagID, Title Table: ItemTag Columns: ItemID, TagID Table: Image Columns: ImageID, Path, Size, UploadDate Table: ItemImage Columns: ItemID, ImageID The items can have more than one image so i have a extra table "...

Worpress WorkFlow Modfications

Hi All WordPress Lovers, I would like to ask a help about Zensor which is a plugin that you publish a post then a moderator approves the post to be published on the wordpress blog site. When a post is awating for approval, each awaiting post is appearing "waiting moderation". But, I dont want any link appears before moderator approval....

What is the difference between union and join?

What is the difference between the SQL keywords union and join? ...

sql: aggregate functions & string join / concatenation

(I'm using postgres) Are there any aggregate functions that work on strings? I want to write a query along the lines of select table1.name, join(' - ', unique(table2.horse)) as all_horses from table1 inner join table2 on table1.id = table2.fk group by table1.name Given these 2 tables: | table1 | | table2 ...

Set time part of datetime variable to 18:00

Hi. I need to set datetime variable to two days from now but it's time part must be 18:00. For example if i call getdate() now i'll get 2010-05-17 13:18:07.260. I need to set it to 2010-05-19 18:00:00.000. Does anybody have a good snippet for that or any ideas how to do it right? ...

How to log subsonic3 sql

Hi, I'm starting to develop a new asp.net application based on subsonic3 (for queries) and log4net (for logs) and would like to know how to interface subsonic3 with log4net so that log4net logs the underlying sql used by subsonic. This is what I have so far: public static IEnumerable<arma_ocorrencium> ListArmasOcorrencia() { ...

SQL to search duplicates

I have a table for animals like Lion Tiger Elephant Jaguar List item Cheetah Puma Rhino I want to insert new animals in this table and I am t reading the animal names from a CSV file. Suppose I got following names in the file Lion,Tiger,Jaguar as these animals are already in "Animals" table, What should be a single SQL query tha...

SQL Query over three different tables

i got three tables CATS id name ------------------------------ 1 category1 2 category2 3 category3 4 category4 PRODUCT id name ------------------------------ 1 product1 2 product2 ZW-CAT-PRODUCT id_cats id_product ---------------------------...

Selecting all tables with no records

I need to display all tables that have zero records. I tried, select * from user_all_tables where (select count(*) from user_all_tables)=0; But it doesn't seem to work. How should I go about redesigning this query? Thanks. ...

Linq2Sql - attempting to update but the Set statement in sql is empty

This is weird ... done updates loads of times before but cannot spot why this is different. although I am using .net 4.0 now - however i doubt its a bug in its L2S implementation. Its not like this is a wierd and wonderful application of it. Although i am fairly sure this code worked whilst i was using the RC. I have also managed to rep...

SQL Statement sorting nvarchar

STD-00-1 STD-00-2 STD-00-10 STD-00-1(T) STD-00-2(T) STD-00-10(T) STD-05-1 STD-05-2 STD-05-10 STD-05-1(T) STD-05-2(T) STD-05-10(T) WIP-00-1 WIP-00-1(T) What is the best way to achieve this? ...

[ADVICE] .NET Desktop Application - Client Server C#, SQL

Hi guys, Recently I've being given a chance to develop a PMS (Practice Management System) software for a small physiotherapy clinic. I'm a computer science student and my course is predominately told on Linux. However, my client runs all their computers on vista or Windows 7. My ideas are to develop the client front end in Visual C# ...

SQL Server 2005 user permissions

I have created a database and some dbo.tables. Now I want to create a user that are can read and write to these tables, but not modify or drop. However I want this user to be able to create own tables and let him do what he want with these. Is this possible? Could someone explain how this can be done? ...

Help with MySQL query

I have a table that contains the next columns: ip(varchar 255), index(bigint 20), time(timestamp) each time something is inserted there, the time column gets current timestamp. I want to run a query that returns all the rows that have been added in the last 24 hours. This is what I try to execute: SELECT ip, index FROM users WHERE ip...

Problem with Oracle/SQL ORDER BY Statement

Hi, i have the following content inside an varchar2 column: 10.1.2.3 10.2.3.4 8.3.4.1 8.3.2.1 4.2.1.3 4.3.2.1 9.3.1.2 When i query the database i need an result ordered: 4.... 8.... 9.... 10... the NLS_SORT parameter is set to german, an simple "order by COLUMN DESC/ASC" is not working like excepted. It return...