Search Results

Search found 7127 results on 286 pages for 'calculated columns'.

Page 29/286 | < Previous Page | 25 26 27 28 29 30 31 32 33 34 35 36  | Next Page >

  • SQL - Order against two columns at the same time (intersecting)

    - by Alex
    I have a table with the fields CommonName and FirstName. Only either field has data, never both. Is there a way to order rows in an intersecting manner on SQL Server? Example: CommonName FirstName Bern Wade Ashley Boris Ayana I want records ordered like this: CommonName FirstName Ashley Ayana Bern Boris Wade Is this possible, and if so, 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

  • transform a matrix wtih 2 columns into a multimap

    - by Derek
    Hi, I am wondering if there is a way to transform a matrix of 2 column into a multimap or list of list. The first column of the matrix is an id (with possibly duplicated entries) and the 2nd column is some value. For example, if I have to following matrix m<-matrix(c(1,2,1,3,2,4), c(3,2)) i would like to transform it into the following list [[1]] 3,4 [[2]] 2 Thanks, Derek

    Read the article

  • Rows in their own columns depending on their date and simbolized by 'x'

    - by Chandradyani
    Dear All, please help me since I'm newbie in SQL Server. I have a select query that currently produces the following results: DoctorName Team Visit date dr. As A 5 dr. Sc A 4 dr. Gh B 6 dr. Nd C 31 dr As A 7 Using the following query: SELECT d.DoctorName, t.TeamName, ca.VisitDate FROM cActivity AS ca INNER JOIN doctor AS d ON ca.DoctorId = d.Id INNER JOIN team AS t ON ca.TeamId = t.Id WHERE ca.VisitDate BETWEEN '1/1/2010' AND '1/31/2010' I want to produce the following: DoctorName Team 1 2 3 4 5 6 7 ... 31 Visited dr. As A x x ... 2 times dr. Sc A x ... 1 times dr. Gh B x ... 1 times dr. Nd C ... X 1 times

    Read the article

  • How to check for mutual existence of Fields in same table in Two columns

    - by ranabra
    I tried using "Exist" and "IN". Not only did I not succeed, it didn't seem as an efficient solution. Here is a simplified example: TblMyTable WorkerUserName  -  WorkerDegree  -  ManagerUserName  -  ManagerDegree I need a query where there is a mutual connection / existence. What I mean is only where the worker, ex. "John" has a manager named "Mary", and where Mary the manager has a worker named "John". John the worker can have several managers and Mary the manager can have several workers. So the result will be (the order doesn't matter) ideally in one line: John - BSc  --  Mary - M.A. or Mary - M.A.  --  John - BSc The punchline is it's only one table. it is not really managers and workers, this is just a simplification of the situation. In the real situation both are equal, in a Table of names of users working with other users. Database is SQL 2005. Many thanx in advance  

    Read the article

  • Why can't I set boolean columns with update?

    - by Benjamin Oakes
    I'm making a user administration page. For the system I'm creating, users need to be approved. Sometimes, there will be many users to approve, so I'd like to make that easy. I'm storing this as a boolean column called approved. I remembered the Edit Multiple Individually Railscast and thought it would be a great fit. However, I'm running into problems which I traced back to ActiveRecord::Base#update. update works fine in this example: >> User.all.map(&:username) => ["ben", "fred"] >> h = {"1"=>{'username'=>'benjamin'}, "2"=>{"username"=>'frederick'}} => {"1"=>{"username"=>"benjamin"}, "2"=>{"username"=>"frederick"}} >> User.update(h.keys, h.values) => ... >> User.all.map(&:username) => ["benjamin", "frederick"] But not this one: >> User.all.map(&:approved) => [true, nil] >> h = {"1"=>{'approved'=>'1'}, "2"=>{'approved'=>'1'}} >> User.update(h.keys, h.values) => ... >> User.all.map(&:approved) => [true, nil] Chaging from '1' to true didn't make a difference when I tested. What am I doing wrong?

    Read the article

  • using or in mysql and merging columns

    - by Pradyut Bhattacharya
    I can select using or with the sql statement select f.userid, f.friend_userid from friends f where userid = 1 or friend_userid = 1; now in the output i have to merge the two rows(userid and friend_userid) into one row such that only the rows without 1 are displayed I m using mysql.... Thanks Pradyut India

    Read the article

  • linq get sum of two columns in one query

    - by Axarydax
    Hi, let's say that I have a table called Items (ID int, Done int, Total int) I can do it by two queries: int total = m.Items.Sum(p=>p.Total) int done = m.Items.Sum(p=>p.Done) But I'd like to do it in one query, something like this: var x = from p in m.Items select new { Sum(p.Total), Sum(p.Done)}; Surely there is a way to call aggregate functions from LINQ syntax...?

    Read the article

  • mysql index optimization for a table with multiple indexes that index some of the same columns

    - by Sean
    I have a table that stores some basic data about visitor sessions on third party web sites. This is its structure: id, site_id, unixtime, unixtime_last, ip_address, uid There are four indexes: id, site_id/unixtime, site_id/ip_address, and site_id/uid There are many different types of ways that we query this table, and all of them are specific to the site_id. The index with unixtime is used to display the list of visitors for a given date or time range. The other two are used to find all visits from an IP address or a "uid" (a unique cookie value created for each visitor), as well as determining if this is a new visitor or a returning visitor. Obviously storing site_id inside 3 indexes is inefficient for both write speed and storage, but I see no way around it, since I need to be able to quickly query this data for a given specific site_id. Any ideas on making this more efficient? I don't really understand B-trees besides some very basic stuff, but it's more efficient to have the left-most column of an index be the one with the least variance - correct? Because I considered having the site_id being the second column of the index for both ip_address and uid but I think that would make the index less efficient since the IP and UID are going to vary more than the site ID will, because we only have about 8000 unique sites per database server, but millions of unique visitors across all ~8000 sites on a daily basis. I've also considered removing site_id from the IP and UID indexes completely, since the chances of the same visitor going to multiple sites that share the same database server are quite small, but in cases where this does happen, I fear it could be quite slow to determine if this is a new visitor to this site_id or not. The query would be something like: select id from sessions where uid = 'value' and site_id = 123 limit 1 ... so if this visitor had visited this site before, it would only need to find one row with this site_id before it stopped. This wouldn't be super fast necessarily, but acceptably fast. But say we have a site that gets 500,000 visitors a day, and a particular visitor loves this site and goes there 10 times a day. Now they happen to hit another site on the same database server for the first time. The above query could take quite a long time to search through all of the potentially thousands of rows for this UID, scattered all over the disk, since it wouldn't be finding one for this site ID. Any insight on making this as efficient as possible would be appreciated :) Update - this is a MyISAM table with MySQL 5.0. My concerns are both with performance as well as storage space. This table is both read and write heavy. If I had to choose between performance and storage, my biggest concern is performance - but both are important. We use memcached heavily in all areas of our service, but that's not an excuse to not care about the database design. I want the database to be as efficient as possible.

    Read the article

  • HTML CSS two columns

    - by Marki
    If my HTML says something along the following <div class="container"> <div class="element"> </div> <div class="element"> </div> [...] <div class="element"> </div> </div> is it then possible to align those elements as if they were in a two-column table? I.e. with 7 elements there would be 4 rows, with the last row only having one element. (The elements themselves have NO special classes or ids like right,left,etc.)

    Read the article

  • XSLT: Whole table columns count.

    - by kalininew
    Good afternoon, gentlemen. Please help us solve the problem, I do not have enough brains to solve it by myself. There is a table, you must define "simple" it or "complicated". Table "simple" if each row contain only two column, otherwise it is "complicated" table. How to do this means xslt.

    Read the article

  • Get sum of two columns in one LINQ query

    - by Axarydax
    Hi, let's say that I have a table called Items (ID int, Done int, Total int) I can do it by two queries: int total = m.Items.Sum(p=>p.Total) int done = m.Items.Sum(p=>p.Done) But I'd like to do it in one query, something like this: var x = from p in m.Items select new { Sum(p.Total), Sum(p.Done)}; Surely there is a way to call aggregate functions from LINQ syntax...?

    Read the article

  • XSL: List divided into columns.

    - by kalininew
    Hello, help me please. There is a list of nodes. <list> <item>1</item> <item>2</item> <item>3</item> <item>4</item> <item>5</item> <item>6</item> <item>7</item> and so on... </list> Need to divide the list of "n" (arbitrary number) equal parts. If the number of nodes is not divided equally, then let the last set of nodes will contain the remainder of the division. For example, if the input list contains 33 elements and the output should have 4 parts with uniformly distributed elements. At the exit to get 3 parts to 9 of elements and one part with 6 elements in the sum of 33.

    Read the article

  • vim command to restructure/force text to 80 columns

    - by wickedchicken
    I know there are ways to automatically set the width of text in vim using set textwidth (like http://stackoverflow.com/questions/235439/vim-80-column-layout-concerns). What I am looking for is something similar to = (the indent line command) but to wrap to 80. The use case is sometimes you edit text with textwidth and after joining lines or deleting/adding text it comes out poorly wrapped. Ideally, this command would completely reorganize the lines I select and chop off long lines while adding to short ones. An example: long line is long! short After running the command (assuming the wrap was 13 cols): long line is long! short If this isn't possible with a true vim command, perhaps there is a command-line program which does this that I can pipe the input to?

    Read the article

  • Rows in their own columns depending on their date and symbolized by 'x'

    - by Chandradyani
    Dear All, please help me since I'm newbie in SQL Server. I have a select query that currently produces the following results: DoctorName Team Visit date dr. As A 5 dr. Sc A 4 dr. Gh B 6 dr. Nd C 31 dr As A 7 Using the following query: SELECT d.DoctorName, t.TeamName, ca.VisitDate FROM cActivity AS ca INNER JOIN doctor AS d ON ca.DoctorId = d.Id INNER JOIN team AS t ON ca.TeamId = t.Id WHERE ca.VisitDate BETWEEN '1/1/2010' AND '1/31/2010' I want to produce the following: DoctorName Team 1 2 3 4 5 6 7 ... 31 Visited dr. As A x x ... 2 times dr. Sc A x ... 1 times dr. Gh B x ... 1 times dr. Nd C ... X 1 times

    Read the article

  • NHibernate - Retrieve specific columns and count using criteria querie

    - by Cristian Sapino
    This is my mapping file: This is the other with joined-subclass class name="CRMStradCommon.Entities.ContactoEntity,CRMStradCommon" table="contacto" dynamic-update="true" Haw can I make this query with Criteria? SELECT contacto.id, contacto.nombre, persona.apellido, COUNT(*) AS Cant FROM contacto INNER JOIN oportunidad ON contacto.id = oportunidad.dueno LEFT OUTER JOIN persona ON contacto.id = persona.id LEFT OUTER JOIN empresa ON contacto.id = empresa.id GROUP BY contacto.id, contacto.nombre, persona.apellido ORDER BY contacto.nombre, persona.apellido Thanks a lot!

    Read the article

  • Speed up SQL Server Fulltext Index through Text Duplication of Non-Indexed Columns

    - by Alex
    1) I have the text fields FirstName, LastName, and City. They are fulltext indexed. 2) I also have the FK int fields AuthorId and EditorId, not fulltext indexed. A search on FirstName = 'abc' AND AuthorId = 1 will first search the entire fulltext index for 'abc', and then narrow the resultset for AuthorId = 1. This is bad because it is a huge waste of resources as the fulltext search will be performed on many records that won't be applicable. Unfortunately, to my knowledge, this can't be turned around (narrow by AuthorId first and then fulltext-search the subset that matches) because the FTS process is separate from SQL Server. Now my proposed solution that I seek feedback on: Does it make sense to create another computed column which will be included in the fulltext search which will identify the Author as text (e.g. AUTHORONE). That way I could get rid of the AuthorId restriction, and instead make it part of my fulltext search (a search for 'abc' would be 'abc' and 'AUTHORONE' - all executed as part of the fulltext search). Is this a good idea or not? Why?

    Read the article

  • MS Excel - Copying columns from multiple worksheets into a single worksheet based on some condition

    - by SpikETidE
    Hi everyone... Consider i have 4 workbooks with the following structure... 1. Main.xlsx Name Jan Feb Mar A B C 2. Jan.xlsx Name Jan A 3.3 B 6.4 C 5.3 3. Feb.xlsx Name Feb A 1.3 B 3.4 C 5.5 4. Mar.xlsx Name Mar A 1.3 B 3.4 C 5.5 I need to combine them like 1. Main.xlsx Name Jan Feb Mar A 3.3 1.3 1.3 B 6.4 3.4 3.4 C 5.3 5.5 5.5 And i need to automate the process... Can someone enlighten me about the possible options that i have to do this...? Thanks for your time....

    Read the article

  • Updating nullability of columns in SQL 2008

    - by Shaul
    I have a very wide table, containing lots and lots of bit fields. These bit fields were originally set up as nullable. Now we've just made a decision that it doesn't make sense to have them nullable; the value is either Yes or No, default No. In other words, the schema should change from: create table MyTable( ID bigint not null, Name varchar(100) not null, BitField1 bit null, BitField2 bit null, ... BitFieldN bit null ) to create table MyTable( ID bigint not null, Name varchar(100) not null, BitField1 bit not null, BitField2 bit not null, ... BitFieldN bit not null ) alter table MyTable add constraint DF_BitField1 default 0 for BitField1 alter table MyTable add constraint DF_BitField2 default 0 for BitField2 alter table MyTable add constraint DF_BitField3 default 0 for BitField3 So I've just gone in through the SQL Management Studio, updating all these fields to non-nullable, default value 0. And guess what - when I try to update it, SQL Mgmt studio internally recreates the table and then tries to reinsert all the data into the new table... including the null values! Which of course generates an error, because it's explicitly trying to insert a null value into a non-nullable column. Aaargh! Obviously I could run N update statements of the form: update MyTable set BitField1 = 0 where BitField1 is null update MyTable set BitField2 = 0 where BitField2 is null but as I said before, there are n fields out there, and what's more, this change has to propagate out to several identical databases. Very painful to implement manually. Is there any way to make the table modification just ignore the null values and allow the default rule to kick in when you attempt to insert a null value?

    Read the article

  • finding numbers of days between two date to make a dynamic columns

    - by Chandradyani
    Dear all, I have a select query that currently produces the following results: DoctorName Team 1 2 3 4 5 6 7 ... 31 Visited dr. As   A                             x    x ...      2 times dr. Sc   A                          x          ...      1 times dr. Gh   B                                  x ...      1 times dr. Nd   C                                     ... x    1 times Using the following query: DECLARE @startDate = '1/1/2010', @enddate = '1/31/2010' SELECT d.doctorname, t.teamname, MAX(CASE WHEN ca.visitdate = 1 THEN 'x' ELSE NULL END) AS 1, MAX(CASE WHEN ca.visitdate = 2 THEN 'x' ELSE NULL END) AS 2, MAX(CASE WHEN ca.visitdate = 3 THEN 'x' ELSE NULL END) AS 3, ... MAX(CASE WHEN ca.visitdate = 31 THEN 'x' ELSE NULL END) AS 31, COUNT(*) AS visited FROM CACTIVITY ca JOIN DOCTOR d ON d.id = ca.doctorid JOIN TEAM t ON t.id = ca.teamid WHERE ca.visitdate BETWEEN @startdate AND @enddate GROUP BY d.doctorname, t.teamname the problem is I want to make the column of date are dynamic for example if ca.visitdate BETWEEN '2/1/2012' AND '2/29/2012' so the result will be : DoctorName Team 1 2 3 4 5 6 7 ... 29 Visited dr. As   A                             x    x ...      2 times dr. Sc   A                          x          ...      1 times dr. Gh   B                                  x ...      1 times dr. Nd   C                                     ... x    1 times Can somebody help me how to get numbers of days between two date and help me revised the query so it can looping MAX(CASE WHEN ca.visitdate = 1 THEN 'x' ELSE NULL END) AS 1 as many as numbers of days? Please please

    Read the article

  • Mysql order by using two columns

    - by Krishna Priya
    Hi, I am using a table which has Createdon and Lastmodifiedon fields, I have to display first the newly added record based on createdon and then followed by lastmodifiedon records using mysql. I have tried adding "ORDER BY Createdon,Lastmodifiedon desc" at the end of the query;but sorting based on first column only occurs. Anyone please help in this issue Thanks.

    Read the article

  • SQL Server 2005, wide indexes, computed columns, and sargable queries

    - by luksan
    In my database, assume we have a table defined as follows: CREATE TABLE [Chemical]( [ChemicalId] int NOT NULL IDENTITY(1,1) PRIMARY KEY, [Name] nvarchar(max) NOT NULL, [Description] nvarchar(max) NULL ) The value for Name can be very large, so we must use nvarchar(max). Unfortunately, we want to create an index on this column, but nvarchar(max) is not supported inside an index. So we create the following computed column and associated index based upon it: ALTER TABLE [Chemical] ADD [Name_Indexable] AS LEFT([Name], 20) CREATE INDEX [IX_Name] ON [Chemical]([Name_Indexable]) INCLUDE([Name]) The index will not be unique but we can enforce uniqueness via a trigger. If we perform the following query, the execution plan results in a index scan, which is not what we want: SELECT [ChemicalId], [Name], [Description] FROM [Chemical] WHERE [Name]='[1,1''-Bicyclohexyl]-2-carboxylic acid, 4'',5-dihydroxy-2'',3-dimethyl-5'',6-bis[(1-oxo-2-propen-1-yl)oxy]-, methyl ester' However, if we modify the query to make it "sargable," then the execution plan results in an index seek, which is what we want: SELECT [ChemicalId], [Name], [Description] FROM [Chemical] WHERE [Indexable_Name]='[1,1''-Bicyclohexyl]-' AND [Name]='[1,1''-Bicyclohexyl]-2-carboxylic acid, 4'',5-dihydroxy-2'',3-dimethyl-5'',6-bis[(1-oxo-2-propen-1-yl)oxy]-, methyl ester' Is this a good solution if we control the format of all queries executed against the database via our middle tier? Is there a better way? Is this a major kludge? Should we be using full-text indexing?

    Read the article

< Previous Page | 25 26 27 28 29 30 31 32 33 34 35 36  | Next Page >