sql-view

How to create View (SQL) from Entity Framework in ABP Framework

笑着哭i 提交于 2019-12-24 18:13:05
问题 My situation is that I need to query from another database and show the result in my application. Both databases are on the same server. I came up with an idea on creating SQL-View in my database which would query the other database for values that I want. But I am not quite sure on how I can create or map SQL-View from the ABP framework? I am using the full .Net framework with the Angular template. 回答1: Creating View is not directly supported in EF. So you can try the below approach. Create

MySQL Views: Referencing one calculated field (by name) in another calculated field

泄露秘密 提交于 2019-12-24 02:24:28
问题 How can I define a view that has two calculated fields, for instance... ('TableName'.'BlueSquares' + 'TableName'.'RedSquares') AS TotalSquares, ('TableName'.'BlueCirles' + 'TableName'.'RedCircles') AS TotalCircles ... and create a third calculated field that's based on the first two calculated fields, as in... ('ViewName'.'TotalSquares' + 'ViewName'.'TotalCircles') AS TotalShapes ...? When I reference the first two calculated fields by name, I get a message that the fields are unknown. Thanks

How can I use SQL Server Table Views as Rails Models (Read Only)?

假如想象 提交于 2019-12-22 11:33:44
问题 I'm using SQL Server as my database for my Rails project. I'm trying to create some models to use for a 3rd party database and only want to read from this database. So I made a view of the table I wanted to create an object for and then I wanted to point my active record model to it. However, in rails console I don't get back expected results. The only example that gives back some correct information is when I do a count on the object as shown in Example 3 below. I'm using the following gems

Select a sequence between two numbers on MySQL

不打扰是莪最后的温柔 提交于 2019-12-21 04:51:17
问题 I have this table named people with two dates on MySQL: | Name | start_date | end_date | | John | 2007-03-01 | 2009-10-12 | | Mike | 2001-06-06 | 2010-12-01 | I want to create a view that lets me search by activity year, being activity year any year between the start_date and the end_date . So, I'd like to get a field with a sequence of years, like this: | Name | activity_years | | John | 2007,2008,2009 | | Mike | 2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 | I've tried some approaches,

creating django model for existing database/sql view?

℡╲_俬逩灬. 提交于 2019-12-20 15:22:37
问题 I have inserted a definition for a view in $template_dir/sql/$someTableName.sql file. (create or replace view) so every time I run syncdb , the db views are created. Can I create in models.py a python class which accesses that view? Is it better practice to just use python's raw sql functionality instead? ---EDIT--- Another problem I have is that the view doesn't have a primary key, but django seems to be assuming there will be one because I get an error caught an exception while rendering:

Prepend table name to each column in a result set in SQL? (Postgres specifically)

让人想犯罪 __ 提交于 2019-12-18 20:49:51
问题 How can I get the label of each column in a result set to prepend the name if its table? I want this to happen for queries on single tables as well as joins. Example: SELECT first_name, last_name FROM person; I want the results to be: | person.first_name | person.last_name | |-------------------|------------------| | Wendy | Melvoin | | Lisa | Coleman | I could use "AS" to define an alias for each column, but that would be tedious. I want this to happen automatically. SELECT first_name AS

Prepend table name to each column in a result set in SQL? (Postgres specifically)

两盒软妹~` 提交于 2019-12-18 20:48:07
问题 How can I get the label of each column in a result set to prepend the name if its table? I want this to happen for queries on single tables as well as joins. Example: SELECT first_name, last_name FROM person; I want the results to be: | person.first_name | person.last_name | |-------------------|------------------| | Wendy | Melvoin | | Lisa | Coleman | I could use "AS" to define an alias for each column, but that would be tedious. I want this to happen automatically. SELECT first_name AS

SQL - CTE vs VIEW

不打扰是莪最后的温柔 提交于 2019-12-18 14:55:40
问题 My question here is what is the difference between CTE and View in SQL . I mean in which case I should use the CTE and which case the View . I know that both are some kind of virtual tables but I can't differentiate their use. I found a similar question here but it's about performance. Update 1: For example: I have a database filled with trades( tbl_trade ). I need to select from 3.5 millions records only the trades that was opened the current month until current time and then manipulate the

How to create a not null column in a view

混江龙づ霸主 提交于 2019-12-18 07:41:13
问题 Given a table like: CREATE TABLE "MyTable" ( "MyColumn" NUMBER NOT NULL ); I want to create a view like: CREATE VIEW "MyView" AS SELECT CAST("MyColumn" AS BINARY_DOUBLE) AS "MyColumn" FROM "MyTable"; Only where the column "MyColumn" is "NOT NULL". In SQL Server this is pretty straight forward: CREATE VIEW [MyView] AS SELECT ISNULL(CAST([MyColumn] AS Float), 0.0) AS [MyColumn] FROM [MyTable]; However the Oracle equivalent results in a "NULL" column: CREATE VIEW "MyView" AS SELECT NVL(CAST(

Why can't SQL Server alter a view in a stored procedure?

﹥>﹥吖頭↗ 提交于 2019-12-18 05:04:33
问题 I'm using MS SQL Server, and I'd like to alter a view from within a stored procedure, by executing something like "alter view VIEWNAME as ([some sql])". A few pages thrown up by google assert that this is not supported directly (and neither are related alter-table statements), but there are also examples of how to work around it using constructions like this: declare @sql varchar(max) select @sql = 'alter view VIEWNAME as ([some sql])' exec(@sql) Writing code as literal strings smells a bit,