To Use Pivot Table as View in SQL Server - sql

I have got a pivot table. I prepared it in SQL. But I cant use this table in View. I using SQL Server 2008.

See this answer to a somewhat related question:
sql-pivoted-table-is-read-only-and-cells-cant-be-edited
You need to make the view updateable via an INSTEAD OF trigger, and there are specific conditions to using that trigger, such as the pivot-table view being fully identifiable to source record-column.

Related

How to query PostgreSQL database table from Access?

I am very new to SQL, MS Access & PostgreSQL. So this might be a very silly question but somehow I can't figure it out. I'm trying to run SQL queries in access and my data is in a PostgreSQL database table which was linked to access by my colleague earlier. When I make this simple query why do I get an error that the table doesn't exist? Is the syntax different for linked database tables? Or is the link not yet established?
You have created a Pass-Through query. This query is executed on the server, not in Access, so you need to use the original table names from the PostgreSQL database.
So it's not FROM public_tb_change but FROM tb_change.
Or maybe FROM public.tb_change, if public isn't the default schema.
I advise to rename your linked tables to the original name (remove public_), that makes things much less confusing. The schema name is automatically added by Access when linking the tables.

FORM on a SQL Query APEX

I am working in Oracle APEX 4.2. I have created Form on Table, Tabular Form and Form on Table with Report. I have tried a lot to create form on a SQL Query but i can't.
I have two Question related of Form on a SQL Query !
First i want to make Form on SQL Query on Two Tables i-e `
Patient_Registration
Pat_Id(Pk),Name,Address,Gender ,Age,Contact
and Patient_Charges
P_Ch_Id(Pk),Patient_Id(Fk),P_Doc_Charges,P_Extra_Charges
Second is that if the from is made then we will be able to make insertions on two tables in one form ?
I *think * I understand your question.
Create a view with your SQL query and then add a Before Insert trigger which does the necessary DML.
Check out some of the sample apps for ideas in this respect.

pushing a datatable from memory into SQL server using ADO.NET

I have a datatable in memory that I got from a non SQL source.
What is the most elegant way, using ADO.NET to push it "as is into a new SQL (2005) server table?
You'd need to do this as a series of steps. Firstly, creating the table via some dynamic SQL. Then you'd need to load the information from memory into the newly created table, potentially using a BULK INSERT.
Or create the table on the SQL Server, read one row at a time, and add it to the table.
CREATE TABLE based on the structure
SQLBulkCopy it

Use Linq to get data from a database based on data in another database

I have a database called MasterDatabase that has table MainIndex with columns Id, Database (nvarchar), Table(nvarchar)
and I have 2 other databases with tables and data.
Is there a way to substitute the FROM statement with results from the MasterDatabase.MainIndex?
Can this be done with LINQ?
Another alternative is to add the table you want to select from from the second database as a view in the master database. You will then be able to map the view as an entity.
:)
You need the Linq Dynamic Query library to accomplish this. It allows you to do string substitutions in your Linq queries.
More info at http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
Or you can access tables from another database by prefixing the tables in your .dbml with either [DatabaseName].[SchemaName].[TableName] or if it's on a differenct server include the [ServerName] as well... Then you wouldn't have to use Dynamic linq

Is there an Access equivalent of the SQL Server NewId() function?

I have written SQL statements (stored in a text document) that load data into a SQL Server database. These statements need to be repeated daily. Some of the statements use the NewId() function to populate a keyed field in the database, and this works fine.
While I'm in the process of writing an application to replicate these statements, I want to use Access queries and macros instead of copying and pasting queries into SQL Server, thus saving me time on a daily basis. All is working fine but I can't find any function that will replace the SQL Server NewId() function. Does one exist or is there a work around?
I'm using SQL Server 2005 and Access 2007.
On top of matt's answer, you could simply use a pass-through query and just use your existing, working queries from MS Access.
A solution would be to insert the stguidgen() function in your code, as you can find it here: http://trigeminal.fmsinc.com/code/guids.bas https://web.archive.org/web/20190129105748/http://trigeminal.fmsinc.com/code/guids.bas
The only workaround I can think of would be to define the column in your access database of type "Replication ID" and make it an autonumber field. That will automatically generate a unique GUID for each row and you won't need to use newid() at all. In SQL server, you would just make the default value for the column "newid()".
Again, there seems to be confusion here.
If I'm understanding correctly:
You have an Access front end.
You have a SQL Server 2005 back end.
What you need is the ability to generate the GUID in the SQL Server table. So, answers taht suggest adding an AutoNumber field of type ReplicationID in Access aren't going to help, as the table isn't a Jet table, but a SQL Server table.
The SQL can certainly be executed as a passthrough query, which will hand off everything to the SQL Server for processing, but I wonder why there isn't a default value for this field in SQL Server? Can SQL Server 2005 tables not have NewId() as the default value? Or is there some other method for having a field populate with a new GUID? I seem to recall something about using GUIDs and marking them "not for replication" (I don't have access to a SQL Server right at the moment to look this up).
Seems to me it's better to let the database engine do this kind of thing, rather than executing a function in your SQL to do it, but perhaps someone can enlighten me on why I'm wrong on that.