Search Results

Search found 1805 results on 73 pages for 'varchar'.

Page 17/73 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • Optimization of SQL query regarding pair comparisons

    - by InfiniteSquirrel
    Hi, I'm working on a pair comparison site where a user loads a list of films and grades from another site. My site then picks two random movies and matches them against each other, the user selects the better of the two and a new pair is loaded. This gives a complete list of movies ordered by whichever is best. The database contains three tables; fm_film_data - this contains all imported movies fm_film_data(id int(11), imdb_id varchar(10), tmdb_id varchar(10), title varchar(255), original_title varchar(255), year year(4), director text, description text, poster_url varchar(255)) fm_films - this contains all information related to a user, what movies the user has seen, what grades the user has given, as well as information about each film's wins/losses for that user. fm_films(id int(11), user_id int(11), film_id int(11), grade int(11), wins int(11), losses int(11)) fm_log - this contains records of every duel that has occurred. fm_log(id int(11), user_id int(11), winner int(11), loser int(11)) To pick a pair to show the user, I've created a mySQL query that checks the log and picks a pair at random. SELECT pair.id1, pair.id2 FROM (SELECT part1.id AS id1, part2.id AS id2 FROM fm_films AS part1, fm_films AS part2 WHERE part1.id <> part2.id AND part1.user_id = [!!USERID!!] AND part2.user_id = [!!USERID!!]) AS pair LEFT JOIN (SELECT winner AS id1, loser AS id2 FROM fm_log WHERE fm_log.user_id = [!!USERID!!] UNION SELECT loser AS id1, winner AS id2 FROM fm_log WHERE fm_log.user_id = [!!USERID!!]) AS log ON pair.id1 = log.id1 AND pair.id2 = log.id2 WHERE log.id1 IS NULL ORDER BY RAND() LIMIT 1 This query takes some time to load, about 6 seconds in our tests with two users with about 800 grades each. I'm looking for a way to optimize this but still limit all duels to appear only once. The server runs MySQL version 5.0.90-community.

    Read the article

  • Convert Military time to string representation

    - by RRUZ
    I have an column declarated as int (called HourMil) wich store the time in military format. i need convert this values to an formated string (HH:MM) example HourMil = 710 -> must be 07:10 HourMil = 1305 -> must be 13:05 Actually i am using this code (and works ok) for convert the column HourMil to the string representation. SELECT SUBSTRING(LEFT('0',4-LEN(CAST(HourMil AS VARCHAR)))+CAST(HourMil AS VARCHAR),1,2)+':'+SUBSTRING(LEFT('0',4-LEN(CAST(HourMil AS VARCHAR)))+CAST(HourMil AS VARCHAR),3,2) FROM MYTABLE but I think this code can be improved.

    Read the article

  • Why was this T-SQL Syntax never implemented?

    - by ChrisA
    Why did they never let us do this sort of thing: Create Proc RunParameterisedSelect @tableName varchar(100), @columnName varchar(100), @value varchar(100) as select * from @tableName where @columnName = @value You can use @value as a parameter, obviously, and you can achieve the whole thing with dynamic SQL, but creating it is invariably a pain. So why didn't they make it part of the language in some way, rather than forcing you to EXEC(@sql)?

    Read the article

  • What are the hibernate annotations used to persist a Map with an enumerated type as a key?

    - by Jason Novak
    I am having trouble getting the right hibernate annotations to use on a Map with an enumerated class as a key. Here is a simplified (and extremely contrived) example. public class Thing { public String id; public Letter startLetter; public Map<Letter,Double> letterCounts = new HashMap<Letter, Double>(); } public enum Letter { A, B, C, D } Here are my current annotations on Thing @Entity public class Thing { @Id public String id; @Enumerated(EnumType.STRING) public Letter startLetter; @CollectionOfElements @JoinTable(name = "Thing_letterFrequencies", joinColumns = @JoinColumn(name = "thingId")) @MapKey(columns = @Column(name = "letter", nullable = false)) @Column(name = "count") public Map<Letter,Double> letterCounts = new HashMap<Letter, Double>(); } Hibernate generates the following DDL to create the tables for my MySql database create table Thing (id varchar(255) not null, startLetter varchar(255), primary key (id)) type=InnoDB; create table Thing_letterFrequencies (thingId varchar(255) not null, count double precision, letter tinyblob not null, primary key (thingId, letter)) type=InnoDB; Notice that hibernate tries to define letter (my map key) as a tinyblob, however it defines startLetter as a varchar(255) even though both are of the enumerated type Letter. When I try to create the tables I see the following error BLOB/TEXT column 'letter' used in key specification without a key length I googled this error and it appears that MySql has issues when you try to make a tinyblob column part of a primary key, which is what hibernate needs to do with the Thing_letterFrequencies table. So I would rather have letter mapped to a varchar(255) the way startLetter is. Unfortunately, I've been fussing with the MapKey annotation for a while now and haven't been able to make this work. I've also tried @MapKeyManyToMany(targetEntity=Product.class) without success. Can anyone tell me what are the correct annotations for my letterCounts map so that hibernate will treat the letterCounts map key the same way it does startLetter?

    Read the article

  • MySQL COUNT() multiple columns

    - by liam
    Hello, I'm trying to fetch the most popular tags from all videos in my database (ignoring blank tags). I also need the 'flv' for each tag. I have this working as I want if each video has one tag: SELECT tag_1, flv, COUNT(tag_1) AS tagcount FROM videos WHERE NOT tag_1='' GROUP BY tag_1 ORDER BY tagcount DESC LIMIT 0, 10 However in my database, each video is allowed three tags - tag_1, tag_2 and tag_3. Is there a way to get the most popular tags reading from multiple columns? The record structure is: +-----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | flv | varchar(150) | YES | | NULL | | | tag_1 | varchar(75) | YES | | NULL | | | tag_2 | varchar(75) | YES | | NULL | | | tag_3 | varchar(75) | YES | | NULL | | +-----------------+--------------+------+-----+---------+----------------+

    Read the article

  • Insert not working

    - by user1642318
    I've searched evreywhere and tried all suggestions but still no luck when running the following code. Note that some code is commented out. Thats just me trying different things. SqlConnection connection = new SqlConnection("Data Source=URB900-PC\SQLEXPRESS;Initial Catalog=usersSQL;Integrated Security=True"); string password = PasswordTextBox.Text; string email = EmailTextBox.Text; string firstname = FirstNameTextBox.Text; string lastname = SurnameTextBox.Text; //command.Parameters.AddWithValue("@UserName", username); //command.Parameters.AddWithValue("@Password", password); //command.Parameters.AddWithValue("@Email", email); //command.Parameters.AddWithValue("@FirstName", firstname); //command.Parameters.AddWithValue("@LastName", lastname); command.Parameters.Add("@UserName", SqlDbType.VarChar); command.Parameters["@UserName"].Value = username; command.Parameters.Add("@Password", SqlDbType.VarChar); command.Parameters["@Password"].Value = password; command.Parameters.Add("@Email", SqlDbType.VarChar); command.Parameters["@Email"].Value = email; command.Parameters.Add("@FirstName", SqlDbType.VarChar); command.Parameters["@FirstName"].Value = firstname; command.Parameters.Add("@LasttName", SqlDbType.VarChar); command.Parameters["@LasttName"].Value = lastname; SqlCommand command2 = new SqlCommand("INSERT INTO users (UserName, Password, UserEmail, FirstName, LastName)" + "values (@UserName, @Password, @Email, @FirstName, @LastName)", connection); connection.Open(); command2.ExecuteNonQuery(); //command2.ExecuteScalar(); connection.Close(); When I run this, fill in the textboxes and hit the button I get...... Must declare the scalar variable "@UserName". Any help would be greatly appreciated. Thanks.

    Read the article

  • select command in mysql doesnot return any row

    - by jeyshree
    i created a database using the command CREATE TABLE login_table2(user_name VARCHAR(32), first_name VARCHAR(32), last_name VARCHAR(32), password VARCHAR(64)); then i inserted a data using command INSERT INTO login_table2(user_name ,first_name , last_name , password ) VALUES('ramya', 'ramya', 'muthu', 'India'); the data got inserted into the table. then i inserted another set of data using command INSERT INTO login_table2(user_name ,first_name , last_name , password ) VALUES('jeyshree', 'jey', 'shree', 'India'); the data got inserted into the table too. then i gave the command SELECT first_name FROM login_table2; the command displayed all the first_ name in the table. however when i gave the command SELECT password FROM login_table2 WHERE user_name = 'ramya'; it does not fetch anything though the entry exist in the table.mention where i am going wrong.awaiting your reply.

    Read the article

  • Microsoft Access - Enter Parameter Value why?

    - by Jane Doe
    I am encountering a problem for my database. Here is the relationships of the database And tried to do the query for how many transactions have movie "Harry_Potter"? so I used SQL query: SELECT COUNT(td.movie) AS number_of_occurrence, td.transaction_number FROM TransactionDetails td, MovieDetails md WHERE md.movie = Harry_Potter But it asks for Harry_Potter enter parameter value why? The relevant SQL statements are CREATE TABLE TransactionDetails ( transaction_number INTEGER PRIMARY KEY, movie VARCHAR(30) NOT NULL, date_of_transaction DATE NOT NULL, member_number INTEGER NOT NULL ) CREATE TABLE MovieDetails ( movie VARCHAR(30) PRIMARY KEY, movie_type VARCHAR(3) NOT NULL, movie_genre VARCHAR(10) NOT NULL ) ALTER TABLE TransactionDetails ADD CONSTRAINT member_number_fk FOREIGN KEY (member_number) REFERENCES LimelightMemberDetails(member_number); ALTER TABLE TransactionDetails ADD CONSTRAINT transaction_number_drink_fk FOREIGN KEY (transaction_number) REFERENCES DrinkTransactionDetails(transaction_number); ALTER TABLE TransactionDetails ADD CONSTRAINT transaction_number_food_fk FOREIGN KEY (transaction_number) REFERENCES FoodTransactionDetails(transaction_number); ALTER TABLE TransactionDetails ADD CONSTRAINT movie_fk FOREIGN KEY (movie) REFERENCES MovieDetails (movie); Thank you for your help! If there is anything wrong with my database design please let me know! thank you!

    Read the article

  • How to insert values using Joins in asp.net stroed procedure?

    - by Samba Siva
    CREATE PROC [dbo].[K_HRM_Insert_VehicleAssign] @vehiclename varchar(50), @empname varchar(50), @updatedby varchar(50), @updatedon datetime as begin insert into K_MasterEmpDetails ME inner join K_HRM_Vehicle_Assign VA on VA.[empname+id] = ME.Firstname +' '+ME.Lastname+' - '+ME.kjlid as ME.Employee (VA.vehiclename,ME.Employee,VA.updatedby,VA.updatedon)values(@vehiclename,@empname, @updatedby,getdate()) end I am getting an error near ME...please help me

    Read the article

  • How do I return the IDENTITY for an inserted record from a stored Proecedure?

    - by user54197
    I am adding data to my database, but would like to retrieve the UnitID that is Auto generated. using (SqlConnection connect = new SqlConnection(connections)) { SqlCommand command = new SqlCommand("ContactInfo_Add", connect); command.Parameters.Add(new SqlParameter("name", name)); command.Parameters.Add(new SqlParameter("address", address)); command.Parameters.Add(new SqlParameter("Product", name)); command.Parameters.Add(new SqlParameter("Quantity", address)); command.Parameters.Add(new SqlParameter("DueDate", city)); connect.Open(); command.ExecuteNonQuery(); } ... ALTER PROCEDURE [dbo].[Contact_Add] @name varchar(40), @address varchar(60), @Product varchar(40), @Quantity varchar(5), @DueDate datetime AS BEGIN SET NOCOUNT ON; INSERT INTO DBO.PERSON (Name, Address) VALUES (@name, @address) INSERT INTO DBO.PRODUCT_DATA (PersonID, Product, Quantity, DueDate) VALUES (@Product, @Quantity, @DueDate) END

    Read the article

  • minutes to time in sql server

    - by Luca Romagnoli
    i've created a function for convert minutes (smallint) in time (varchar(5)) like 58 - 00:58 set QUOTED_IDENTIFIER ON GO Create FUNCTION [dbo].[IntToMinutes] ( @m smallint ) RETURNS nvarchar(5) AS BEGIN DECLARE @c nvarchar(5) SET @c = CAST((@m / 60) as varchar(2)) + ':' + CAST((@m % 60) as varchar(2)) RETURN @c END The problem is when there are minutes < 10 in time like 9 the result of this function is 0:9 i want that the format is 00:09 how can i do that?

    Read the article

  • adding month to EndDate as constraint in Oracle SQL

    - by user2900611
    I've a question regarding Oracle database SQL. my employee each have a project, the end date of the project depends on the no of months that was given to them base on PTerm. Am i right to do it this way? CREATE TABLE PROJECT ( P_ID VARCHAR ( 20 ) NOT NULL, PNAME VARCHAR ( 100 ) NOT NULL, PTERM VARCHAR ( 20 ), PSTARTDATE DATE, PENDDATE DATE, CONSTRAINT PROJECT_PKEY PRIMARY KEY ( P_ID ), CONSTRAINT PROJECT_PTERM CHECK ( PTERM IN ('1 MONTH', '2 MONTH', '3 MONTH') ), CONSTRAINT PROJECT_ENDDATE CHECK ( PENDDATE = (PSTARTDATE + PTERM) ) );

    Read the article

  • SQL CREATE TABLE Error

    - by Adam M-W
    Hi, I've been stuck on this one simple(ish) thing for the last 1/2 hour so I thought I might try to get a quick answer here. What exactly is incorrect about my SQL syntax, assuming I'm using mysql 5.1 CREATE TABLE 'users' ( 'id' MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 'username' VARCHAR(20) NOT NULL, 'password' VARCHAR(40) NOT NULL, 'salt' VARCHAR(40) DEFAULT NULL, 'email' VARCHAR(80) NOT NULL, 'created_on' INT(11) UNSIGNED NOT NULL, 'last_login' INT(11) UNSIGNED DEFAULT NULL, 'active' TINYINT(1) UNSIGNED DEFAULT NULL, ) ENGINE InnoDB; Also, does anyone have any good tutorials about how to use Zend_Auth for complete noobs? Thanks.

    Read the article

  • SQL query problem

    - by Brisonela
    Hi, I'm new to StackOverflow, and new to SQL Server, I'd like you to help me with some troublesome query. This is my database structure(It's half spanish, hope doesn't matter) Database My problem is that I don't now how to make a query that states which team is local and which is visitor(using table TMatch, knowing that the stadium belongs to only one team) This is as far as I can get Select P.NroMatch, (select * from fnTeam (P.TeamA)) as TeamA,(select * from fnTeam (P.TeamB)) as TeamB, (select * from fnEstadium (P.CodEstadium)) as Estadium, (cast(P.GolesTeamA as varchar)) + '-' + (cast(P.GolesTeamA as varchar)) as Score, P.Fecha from TMatch P Using this functions: If object_id ('fnTeam','fn')is not null drop function fnTeam go create function fnTeam(@CodTeam varchar(5)) returns table return(Select Name from TTeam where CodTeam = @CodTeam) go select * from fnTeam ('Eq001') go ----**** If object_id ('fnEstadium','fn')is not null drop function fnEstadium go create function fnEstadium(@CodEstadium varchar(5)) returns table return(Select Name from TEstadium where CodEstadium = @CodEstadium) go I hope I'd explained myself well, and I thank you help in advance

    Read the article

  • What is the fastest way to insert 100 000 records from one database to another?

    - by Pentium10
    I have a mobile application. My client has a large data set ~100.000 records. It's updated frequently. When we sync we need to copy from one database to another. I have attached the second database to the main, and run an insert into table select * from sync.table. This is extremely slow, it takes about 10 minutes I think. I noticed that the journal file gets increased step by step. How can I speed this up? EDITED 1 I have indexes off, and I have journal off. Using insert into table select * from sync.table it still takes 10 minutes. EDITED 2 If I run a query like select id,invitem,invid,cost from inventory where itemtype = 1 order by invitem limit 50 it takes 15-20 seconds. The table schema is: CREATE TABLE inventory ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'serverid' INTEGER NOT NULL DEFAULT 0, 'itemtype' INTEGER NOT NULL DEFAULT 0, 'invitem' VARCHAR, 'instock' FLOAT NOT NULL DEFAULT 0, 'cost' FLOAT NOT NULL DEFAULT 0, 'invid' VARCHAR, 'categoryid' INTEGER DEFAULT 0, 'pdacategoryid' INTEGER DEFAULT 0, 'notes' VARCHAR, 'threshold' INTEGER NOT NULL DEFAULT 0, 'ordered' INTEGER NOT NULL DEFAULT 0, 'supplier' VARCHAR, 'markup' FLOAT NOT NULL DEFAULT 0, 'taxfree' INTEGER NOT NULL DEFAULT 0, 'dirty' INTEGER NOT NULL DEFAULT 1, 'username' VARCHAR, 'version' INTEGER NOT NULL DEFAULT 15 ) Indexes are created like CREATE INDEX idx_inventory_categoryid ON inventory (pdacategoryid); CREATE INDEX idx_inventory_invitem ON inventory (invitem); CREATE INDEX idx_inventory_itemtype ON inventory (itemtype); I am wondering, the insert into ... select * from isn't the fastest built-in way to do massive data copy? EDITED 3 SQLite is serverless, so please stop voting a particular answer, because that is not the answer I'm sure.

    Read the article

  • Dynamic SQL and Funtions

    - by Unlimited071
    Hi all, is there any way of accomplishing something like the following: CREATE FUNCTION GetQtyFromID ( @oricod varchar(15), @ccocod varchar(15), @ocmnum int, @oinnum int, @acmnum int, @acttip char(2), @unisim varchar(15) ) AS BEGIN DECLARE @Result decimal(18,8) DECLARE @SQLString nvarchar(max); DECLARE @ParmDefinition nvarchar(max); --I need to execute a query stored in a cell which returns the calculated qty. --i.e of AcuQry: select @cant = sum(smt) from table where oricod = @oricod and ... SELECT @SQLString = AcuQry FROM OinActUni WHERE (OriCod = @oricod) AND (ActTipCod = @acttip) AND (UniSim = @unisim) AND (AcuEst > 0) SET @ParmDefinition = N' @oricod varchar(15), @ccocod varchar(15), @ocmnum int, @oinnum int, @acmnum int, @cant decimal(18,8) output'; EXECUTE sp_executesql @SQLString, @ParmDefinition, @oricod = @oricod, @ccocod = @ccocod, @ocmnum = @ocmnum, @oinnum = @oinnum, @acmnum = @acmnum, @cant = @result OUTPUT; RETURN @Result END The problem with this approach is that it is prohibited to execute sp_excutesql in a function... What I need is to do something like: select id, getQtyFromID(id) as qty from table The main idea is to execute a query stored in a table cell, this is because the qty of something depends on it's unit. the unit can be days or it can be metric tons, so there is no relation between the units, therefore the need of a specific query for each unit.

    Read the article

  • What's the error in my MySQL statement?

    - by Jim
    The following SQL statement has a syntax error according to phpMyAdmin, but I can't spot what it is. Any ideas? CREATE TABLE allocations( `student_uid` INT unsigned NOT NULL DEFAULT 0, `active` INT unsigned NOT NULL DEFAULT 1, `name` VARCHAR( 255 ) NOT NULL DEFAULT '', `internal_id` VARCHAR( 255 ) DEFAULT '', `tutor_uid` INT NOT NULL DEFAULT 0, `allocater_uid` INT unsigned NOT NULL DEFAULT 0, `time_created` INT NOT NULL DEFAULT 0, `remote_time` FLOAT NOT NULL DEFAULT 0, `next_lesson` VARCHAR NOT NULL DEFAULT -1, PRIMARY KEY ( student_uid ) );

    Read the article

  • how to declare variable in POSTGRE

    - by user307880
    I try to declare a variable in a code like this, but it's doesn't work. Can you tell me what's the problem? ERROR: syntax error at or near "VARCHAR" LINE 2: p_country VARCHAR; DECLARE p_country VARCHAR; p_country : = ''; SELECT p_country;

    Read the article

  • JDBC with JSP fails to insert

    - by StrykeR
    I am having some issues right now with JDBC in JSP. I am trying to insert username/pass ext into my MySQL DB. I am not getting any error or exception, however nothing is being inserted into my DB either. Below is my code, any help would be greatly appreciated. <% String uname=request.getParameter("userName"); String pword=request.getParameter("passWord"); String fname=request.getParameter("firstName"); String lname=request.getParameter("lastName"); String email=request.getParameter("emailAddress"); %> <% try{ String dbURL = "jdbc:mysql:localhost:3306/assi1"; String user = "root"; String pwd = "password"; String driver = "com.mysql.jdbc.Driver"; String query = "USE Users"+"INSERT INTO User (UserName, UserPass, FirstName, LastName, EmailAddress) " + "VALUES ('"+uname+"','"+pword+"','"+fname+"','"+lname+"','"+email+"')"; Class.forName(driver); Connection conn = DriverManager.getConnection(dbURL, user, pwd); Statement statement = conn.createStatement(); statement.executeUpdate(query); out.println("Data is successfully inserted!"); } catch(SQLException e){ for (Throwable t : e) t.printStackTrace(); } %> DB script here: CREATE DATABASE Users; use Users; CREATE TABLE User ( UserID INT NOT NULL AUTO_INCREMENT, UserName VARCHAR(20), UserPass VARCHAR(20), FirstName VARCHAR(30), LastName VARCHAR(35), EmailAddress VARCHAR(50), PRIMARY KEY (UserID) );

    Read the article

  • Excel isn't reading sql exported csv properly

    - by mhopkins321
    I have a batch file that calls sqlcmd to run a command and then export the data as a csv. When viewed in a cell the trasancted date for example shows 35:30.0 but if you click on it the formula bar shows 1/1/1900 2:45:00 PM. I need the full timestamp to show in the cell. Any ideas? The batch file is the following sqlcmd -S server -U username -P password -d database -i "D:\path\sqlScript.sql" -s "," > D:\path\report.csv -I -W -k 1 The script is the following. Now I currently have them cast as varchars, but that's simply because i've tried to change it a bit. Varchar doesn't work either. SET NOCOUNT ON; select top(10)BO.Status, cast(tradeDate AS varchar) AS Trade_Date, CAST(closingTime AS varchar) AS Closing_Time, CAST(openingTime AS varchar) AS openingTime FROM GIANT COMPLICATED JOINS OF ALL SORTS OF TABLES

    Read the article

  • How do I drop 'NOT NULL' from a column in MySQL?

    - by Will
    A show create table command shows the following: 'columnA' varchar(6) NOT NULL DEFAULT ''; How do I modify that column so that the not null is removed? I need it to be: 'columnA' varchar(6) DEFAULT NULL; I thought the following would work, but it has no effect: ALTER TABLE tbl_name MODIFY columnA varchar(6) DEFAULT NULL;

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >