Search Results

Search found 37012 results on 1481 pages for 'sql query'.

Page 134/1481 | < Previous Page | 130 131 132 133 134 135 136 137 138 139 140 141  | Next Page >

  • SQLAlchemy custom query column

    - by thrillerator
    I have a declarative table defined like this: class Transaction(Base): __tablename__ = "transactions" id = Column(Integer, primary_key=True) account_id = Column(Integer) transfer_account_id = Column(Integer) amount = Column(Numeric(12, 2)) ... The query should be: SELECT id, (CASE WHEN transfer_account_id=1 THEN -amount ELSE amount) AS amount FROM transactions WHERE account_id = 1 OR transfer_account_id = 1 My code is: query = Transaction.query.filter_by(account_id=1, transfer_account_id=1) query = query.add_column(func.case(...).label("amount") But it doesn't replace the amount column. Been trying to do this with for hours and I don't want to use raw SQL.

    Read the article

  • Sql query listing Fathers and childs with joins, how to distinct them?

    - by DaNieL
    Having those tables: table_n1: | t1_id | t1_name | | 1 | foo | table_n2: | t2_id | t1_id | t2_name | | 1 | 1 | bar | I need a query that gives me two result: | names | | foo | | foo / bar | But i cant figure out the right way. I wrote this one: SELECT CONCAT_WS(' / ', table_n1.t1_name, table_n2.t2_name) AS names FROM table_n1 LEFT JOIN table_n2 ON table_n2.t1_id = table_n1.t1_id that works for an half: this only return the 2° row (in the example above): | names | | foo - bar | This query return the 'father' (table_n1) name only when it doesnt have 'childs' (table_n2). How can i fix it?

    Read the article

  • Is it poor practice to build an SQL query using WHERE 1=1 AND ...

    - by Rob
    I'm writing a script that builds an SQL query by concatenating the string and adding conditions to the WHERE clause as needed. Would it be better practice to use WHERE 1=1 so that the first condition is satisfied and the script can just concatenate an AND x = 'y' to the query, or should I write the extra code to check if a clause has been added and if not, add the AND ? Confusing question, I know. Let me know if I need to be more clear. Rob

    Read the article

  • What are the SQL Server query syntax not supported by MySQL?

    - by ANP
    I am working in a project where we are using SQL Server database currently. But recently a decision has been taken that the database will be changed to MySQL. I am not using any stored procedures, views, triggers, user defined functions, etc. But I think even then some queries written for SQL Server will not be supported by MySQL. Can anyone help: what are the things that I have to check (and change) so that all the queries will work properly for MySQL also?

    Read the article

  • MySql: make this query faster… is there a way ? PART TWO

    - by robert
    This is part two of the question: http://stackoverflow.com/questions/2913639/mysql-make-this-query-faster-theres-a-way this query still run slowly: SELECT b.id, b.name, c.name FROM bookcorr as a JOIN books as b on b.id = a.books_id = JOIN Library as c on c.id = a.library_id WHERE a.category_id = '2521' AND a.library_id = '4983' ORDER BY b.name ASC LIMIT 0,15 Any suggest ?

    Read the article

  • What is the best way to determine what's locking up SQL Server using a query?

    - by Aplato
    Recently our SQL Server is getting bogged down by something. I was wondering what is the best way to check what could be causing the problem by querying the database. This is the best I've found so far: SELECT SPID = s.spid , BlockingSPID = s.blocked , DatabaseName = DB_NAME(s.dbid) , ProgramName = s.program_name , [Status] = s.[status] , LoginName = s.loginame , ObjectName = OBJECT_NAME(objectid, s.dbid) , [Definition] = CAST([text] AS VARCHAR(MAX)) FROM sys.sysprocesses s CROSS APPLY sys.dm_exec_sql_text (sql_handle) WHERE s.spid > 50 ORDER BY DatabaseName , loginName

    Read the article

  • Nested SQL Select statement fails on SQL Server 2000, ok on SQL Server 2005

    - by Jay
    Here is the query: INSERT INTO @TempTable SELECT UserID, Name, Address1 = (SELECT TOP 1 [Address] FROM (SELECT TOP 1 [Address] FROM [UserAddress] ua INNER JOIN UserAddressOrder uo ON ua.UserID = uo.UserID WHERE ua.UserID = u.UserID ORDER BY uo.AddressOrder ASC) q ORDER BY AddressOrder DESC), Address2 = (SELECT TOP 1 [Address] FROM (SELECT TOP 2 [Address] FROM [UserAddress] ua INNER JOIN UserAddressOrder uo ON ua.UserID = uo.UserID WHERE ua.UserID = u.UserID ORDER BY uo.AddressOrder ASC) q ORDER BY AddressOrder DESC) FROM User u In this scenario, users have multiple address definitions, with an integer field specifying the preferred order. "Address2" (the second preferred address) attempts to take the top two preferred addresses, order them descending, then take the top one from the result. You might say, just use a subquery which does a SELECT for the record with "2" in the Order field, but the Order values are not contiguous. How can this be rewritten to conform to SQL 2000's limitations? Very much appreciated.

    Read the article

  • Putting data from local SQL database to remote SQL database without remote SQL access enabled (PHP)

    - by Shyam
    Hi, I have a local database, and all the tables are defined. Eventually I need to publish my data remotely, which I can do easily with PHPmyadmin. Problem however is that my remote host doesn't allow remote SQL connections at all, so writing a script that does a mysqldump and run it through a client (which would've been ideal) won't help me here. Since the schema won't change, but the data will, I need some kind of PHP client that works "reverse". My question is if such a client exists and what would be recommended to use (by experience). I just need an one way trip here, from my local database (Rails) to the remote database (supports PHP), preferable as simple and slick as possible. Thank you for your replies, comments and feedback!

    Read the article

  • SQL Server 2008 DBNETLIB error

    - by Joseph
    Hi all Our ASp.net applications getting error as below" [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied " But i can connect with Enterprise manager management studio and Query analaizer with out any issue. It was running these applications with out any issue long time. last one week we are getting this error.If we restart the server .it works then it will come again after 3to 4 hours. We are running on Windows 2003 server. I was seraching and didnt find a solution yet. If anybody knows anything for this error, please post the details to resolve. Thank you in Advance Joseph

    Read the article

  • Linked servers SQLNCLI problem. "No transaction is active"

    - by Felipe Fiali
    Im trying to execute a stored procedure and simply insert its results in a temporary table, and I'm getting the following message: The operation could not be performed because OLE DB provider "SQLNCLI" for linked server "MyServerName" was unable to begin a distributed transaction. OLE DB provider "SQLNCLI" for linked server "MyServerName" returned message "No transaction is active.". My query looks like this: INSERT INTO #TABLE EXEC MyServerName.MyDatabase.dbo.MyStoredProcedure Param1, Param2, Param3 Exact column number, names, the problem is not the result. MSDTC is allowed and started in both computers, Remote procedure calling too. The machines are not in the same domain, but I can execute remote queries from my machine and get the result. I can even execute the stored procedure and see its results, I just can't insert it in another table. Help, please? :)

    Read the article

  • Updating Xml attributes with new values in a SQL Server 2008 table

    - by SMD
    I have a table in SQL Server 2008 that it has some columns. One of these columns is in Xml format and I want to update some attributes. For example my Xml column's name is XmlText and it's value in 5 first rows is such as: <Identification Name="John" Family="Brown" Age="30" /> <Identification Name="Smith" Family="Johnson" Age="35" /> <Identification Name="Jessy" Family="Albert" Age="60" /> <Identification Name="Mike" Family="Brown" Age="23" /> <Identification Name="Sarah" Family="Johnson" Age="30" /> and I want to change all Age attributes that are 30 to 40 such as below: <Identification Name="John" Family="Brown" Age="40" /> <Identification Name="Smith" Family="Johnson" Age="35" /> <Identification Name="Jessy" Family="Albert" Age="60" /> <Identification Name="Mike" Family="Brown" Age="23" /> <Identification Name="Sarah" Family="Johnson" Age="40" />

    Read the article

  • Table fragmentation in SQL server

    - by Joseph
    Hi Anybody have an idea about Table fragmentation in SQL Server(not Index fragmentation).We have a table ,this is the main table and its not storing any data permently,dat come here and goes out continusly. there is no index on this because only insert and delete staements are running frequently. recently We face a huge delay for the response from this table. If we select anything it tooks more than 2 to 5 minuts to return result,even there is very few datas. At last we delete and recreate this table,and now its working very fine. Appreciate If any comments,how this is happening ? Joseph

    Read the article

  • C# WinForms & SQL bindings

    - by vent
    I have a MSSQL database with many tables and relations. I want to bind it to my C# GUI application with text- and combo-boxes. Which one is the best way to do it: (1) Everything done manually by own classes and methods: Import data to dataset or to many datatables separately, then create dictionaries to comboboxes, manually retrieve data to textboxes and create a sql statement if update action will be invoked, or, (2) Done automatically by VS: Connect my controls with BindingSource and BindingNavigator if needed. I know how to deal with the first one, but if the second way would be better, my question is — how to achieve it? I haven't dealt with automatically created databindings and I don't know how to tell to DataBinding property (Key|Value|Text) about relations and current row's ID. And what is the method to cancel/update changes in all GUI elements? I need a simple solution for this scenario. It's a quick-and-dirty academical project, which must only "work" and be as fast implemented as it can. Thanks

    Read the article

  • Microsoft SQL 2005 - using the modulo operator

    - by cc0
    So I have a silly problem, I have not used much MSSQL before, or any SQL for that matter. I basically have a minor mathematical problem that I need solved, and I thought modulo would be good. I have a number of dates in the database, but I need them be rounded off to the closest [dynamic integer] (could be anything from 0 to 5000000) which will be input as a parameter each time this query is called. So I thought I'd use modulo to find the remainder, then subtract that remainder from the date. If there is a better way, or an integrated function, please let me know! What would be the syntax for that? I've tried a lot of things, but I keep getting error messages like integers/floats/decimals can't be used with the modulo operators. I tried casting to all kinds of numeric datatypes. Any help would be appreciated.

    Read the article

  • Send bulk email from SQL Server 2008

    - by dbnewbie
    Hi, I am relatively new to databases,so please forgive me if my query sounds trivial. I need to send bulk email to all the contacts listed in a particular table. The body of the email is stored in a .doc file which begins as Dear Mr. _. The SQL server will read this file, append the last name of the contact in the blank space and send it to the corresponding email address for that last name. Any thoughts on how to proceed with this? Any insights,suggestions,tips will be greatly appreciated. Thanks!

    Read the article

  • Compound IDENTITY column in SQL SERVER 2008

    - by Asaf R
    An Orders table has a CustomerId column and an OrderId column. For certain reasons it's important that OrderId is no longer than 2-bytes. There will be several million orders in total, which makes 2-bytes not enough. A customer will have no more than several thousand orders making 2-bytes enough. The obvious solution is to have the (CustomerId, OrderId) be unique rather than (OrderId) itself. The problem is generating the next Customer's OrderId. Preferably, without creating a separate table for each customer (even if it contains only an IDENTITY column), in order to keep the upper layers of the solution simple. Q: how would you generate the next OrderId so that (CustomerId, OrderId) is unique but OrderId itself is allowed to have repetitions? Does Sql Server 2008 have a built in functionality for doing this? For lack of a better term I'm calling it a Compound IDENTITY column.

    Read the article

  • Accessing Active Directory Role Membership through LDAP using SQL Server 2005

    - by David Neale
    I would like to get a list of Active Directory users along with the security groups they are members of using SQL Server 2005 linked servers. I have the query working to retrieve records but I'm not sure how to access the memberOf attribute (it is a multi-value LDAP attribute). I have this temporary to store the information: DROP TABLE #ADUSERGROUPS CREATE TABLE #ADUSERGROUPS ( sAMAccountName varchar(30), UserGroup varchar(50) ) Each group/user association should be one row. This is my SELECT statement: SELECT sAMAccountName,memberOf FROM OpenQuery(ADSI, '<LDAP://hqdc04/DC=nt,DC=avs>; (&(objectClass=User)(sAMAccountName=9695)(sn=*)(mail=*)(userAccountControl=512)); sAMAccountName,memberOf;subtree') I get this error msg: OLE DB error trace [OLE/DB Provider 'ADSDSOObject' IRowset::GetData returned 0x40eda: Data status returned from the provider: [COLUMN_NAME=memberOf STATUS=DBSTATUS_E_CANTCONVERTVALUE], [COLUMN_NAME=sAMAccountName STATUS=DBSTATUS_S_OK]]. Msg 7346, Level 16, State 2, Line 2 Could not get the data of the row from the OLE DB provider 'ADSDSOObject'. Could not convert the data value due to reasons other than sign mismatch or overflow.

    Read the article

  • SQL Server 2008 database mirroring madness

    - by Dmitri Nesteruk
    I'm trying to get database mirroring to work on SQL Server 2008 between two computers. I checked connectivity, but here's what I end up with: on the principal machine, the server can connect to the mirror but refuses to set up a mirroring partnership due to it being 'unable to connect' (I checked connectivity, everything works). The weird thing has happened on the mirror. First, the mirror now thinks it's being mirrored. Second, after I delete and recover the mirrored database, it goes into Restoring... mode and just gets stuck there. Any ideas you might have on this are appreciated. Thanks!

    Read the article

  • Autoincrementing hierarchical IDs on SQL Server

    - by Ville Koskinen
    Consider this table on SQL Server wordID aliasID value =========================== 0 0 'cat' 1 0 'dog' 2 0 'argh' 2 1 'ugh' WordID is a id of a word which possibly has aliases. AliasID determines a specific alias to a word. So above 'argh' and 'ugh' are aliases to each other. I'd like to be able to insert new words which do not have any aliases in the table without having to query the table for a free wordID value first. Inserting value 'hey' without specifying a wordID or an aliasID, a row looking like this would be created: wordID aliasID value =========================== 3 0 'hey' Is this possible and how?

    Read the article

  • SQL to retrieve aggregated data with computed columns

    - by Remnant
    I have a table that looks like this for about ~30 students: StudentID Course* CourseStatus 1 Math Pass 1 English Fail 1 Science Pass 2 Math Fail 2 English Pass 2 Science Fail etc. *In my actual database the 'Course' column is a CourseID e.g. (1 = Math; 2 = English etc.) which references a 'CourseName' table. I amended the table above just to make it clear the nature of the problem. I want to write a query (stored procedure) in SQL that summarises performance for a given course and returns the following: EXEC usp_GetCourseSummary 'Math' Total Students Total Pass % Pass Total Fail % Fail 25 15 60 10 40 Have been scratching my head on this one for some time. Any ideas?

    Read the article

  • SQL Azure and VS 2010B2 or SSMSE 2008

    - by Vulgrin
    Ok, I see that people have asked this question before, but I'm seeing some conflicting statements. Can I, or can I not, connect directly to my SQL Azure database from SSMSE 2008? I see posts from before November that the SSMS 2008 RC would be able to connect directly - so I don't understand why the newest SSMSE cannot connect. Is it just a problem with the Express version of SSMS? Where can I find the "non-Express" version, if there is one? I can connect to the database via the cancel and connect method - however, you don't get object explorer that way. I see that there are add-ons for VS.Net to allow you to explore the database but I wanted to do it with the base apps if possible. Thanks

    Read the article

  • Having trouble using 'AND' in CONTAINSTABLE SQL SERVER FULL TEXT SEARCH

    - by Joshua
    I've been using FULL-TEXT for awhile but I cannot seem to get the most relevant results sometimes. If I have an field with something like "An Overview of Pain Medicine 5/12/2006" and a user types "An Overview 5/12/2006" So we create a search like: '"An" AND "Overview" AND "5/12/2006"' - 0 results (bad) '"Overview" AND "5/12/2006"' - 1 result (good) The CONTAINSTABLE portion of my query: FROM ce_Activity A INNER JOIN CONTAINSTABLE(View_Activities,(Searchable), @Search) AS KeyTbl ON A.ActivityID = KeyTbl.[KEY] "Searchable" is a field contains the activity title, and start date(converted to string) in one field so it's all search friendly. Why would this happen?

    Read the article

  • Teradata equivalent of persisted computed column (in SQL Server)

    - by Cade Roux
    We have a few tables with persisted computed columns in SQL Server. Is there an equivalent of this in Teradata? And, if so, what is the syntax and are there any limitations? The particular computed columns I am looking at conform some account numbers by removing leading zeros - an index is also created on this conformed account number: ACCT_NUM_std AS ISNULL(CONVERT(varchar(39), SUBSTRING(LTRIM(RTRIM([ACCT_NUM])), PATINDEX('%[^0]%', LTRIM(RTRIM([ACCT_NUM])) + '.' ), LEN(LTRIM(RTRIM([ACCT_NUM]))) ) ), '' ) PERSISTED With the Teradata TRIM function, the trimming part would be a little simpler: ACCT_NUM_std AS COALESCE(CAST(TRIM(LEADING '0' FROM TRIM(BOTH FROM ACCT_NUM))) AS varchar(39)), '' ) I guess I could just make this a normal column and put the code to standardize the account numbers in all the processes which insert into the table. We did this to put the standardization code in one place.

    Read the article

< Previous Page | 130 131 132 133 134 135 136 137 138 139 140 141  | Next Page >