MOSS SQL Query failing in Sharepoint 2010 with Invalid Column error - sharepoint-2010

I have this query that I am trying to make work in SharePoint 2010.
SELECT DISTINCT (UI.tp_Login) AS UI_tp_Login, AUD.nvarchar9 AS AUD_UniqueID
FROM AllUserData AS AUD WITH (NOLOCK) FULL OUTER JOIN
UserInfo AS UI WITH (NOLOCK)
ON AUD.tp_SiteId = UI.tp_SiteID AND AUD.tp_ID = UI.tp_ID
WHERE AUD.tp_DirName like N'%/_catalogs/users'
AND NOT (AUD.tp_ContentType = 'DomainGroup')
AND NOT (AUD.tp_ContentType = 'SharePointGroup')
AND (AUD.nvarchar3 NOT IN ('SHAREPOINT\system','NT AUTHORITY\local service'))
I am getting error invalid column name 'tp_DirName', 'tp_ContentType'.
Looks like SP 2010 database scheme has changed.
I don't have access to the database to I can't see the schema.
Does anyone know what are the new names of these 2 columns in SP 2010?
Thanks for reading.

it is not recommended to directly access sharepoint managed databases. You can access all the data you require using sharepoint object model.

'tp_ContentType' is no more, now is 'tp_ContentTypeId'
corresponding ids:
'0x010B00C7BCF68683E2A64B99CD9B275AEA5859' - sharepoint group
'0x010A00D2995B358A1FA54FBB5D4C473FA55C4B' - domain group
can't find any simular to 'tp_DirName'

Related

MS Office 12.0 Access Database Engine OLE DB Provider driver assigns different data type to text columns, compared with Jet 4 driver

Summary:
A Crystal report is connected to an Access database (amongst others), using a SQL query. One of the columns consists of an expression that is exposed in Crystal as a "TEXT [255]" field when connected to the Access database using the Jet4 DAO driver, but as "Memo" when connected using the Microsoft Office 12.0 Access Database Engine OLE DB Provider. This causes downstream problems.
Details:
I have a Crystal report which consumes data from two different MS Access databases, using separate SQL queries defined in the report. The results are then combined using a table link (a table link is similar to a table join, but operates across tables from different databases, and is processed by Crystal itself, as opposed to running server-side).
The table link is based (on the one side) on a calculated column ("ColumnToLinkOn") in the SQL query, which looks like this (anonymized):
SELECT
Column1 AS Heading1,
Column2 as Heading2,
Left(Column2,6) AS ColumnToLinkOn -- Table link based on this column
FROM NameOfTable
The data type of Column2 in Access is Short Text (as Access 2013 calls it - previously this was known as Text).
Now for the interesting bit: when the connection from Crystal to the Access database is of type Jet4 (DAO), then the data type of ColumnToLinkOn is String [255]. However, if the connection is changed to use the Microsoft Office 12.0 Access Database Engine OLE DB Provider, then Crystal picks it up as Memo (we change the connection type because we need it to work in 32 and 64 bit mode, but there is no 64 bit Jet4 driver). The problem with this is that table links cannot be based on Memo fields, so that renders the link invalid.
My question:
How can I alter the SQL query to cast the data type to a normal text field, so that it can be used in table links? According to the Access documentation, the LEFT function returns Variant (String), which I suspect causes the problem. The source column is not of type memo, so it is clearly the LEFT function that introduces the problem.
I've tried wrapping the result in CStr, like this: CStr(Left(Column2,6)) AS ColumnToLinkOn, but this has made no difference. I also found a hint that said that doing this Replace(Left(Column2,6), "", "") AS ColumnToLinkOn will help, but it didn't. Unfortunately Access also doesn't support the CAST(column AS type) syntax.
I'm using Access 2013 and Crystal Reports 2013.
Any assistance will be greatly appreciated!
If the records are distinct, you can do it like this:
SELECT DISTINCT
Column1 AS Heading1,
Column2 as Heading2,
Left(Column2,6) AS ColumnToLinkOn -- Table link based on this column
FROM NameOfTable
Access can't match on memo fields either, so it has to truncate memo fields to shorttext to find distinct elements.
Another way would be use a Crystal subreport, and link to a formula field on the subreport instead of linking to the table.

MS Access SQL error with Update Query

working on linking data between a SQL Server Database and MS Access. Right now someone is manually calculating Data from a SQL Database report and entering this into Access to run other reports within Access.
I have created a pass through query to pull the relevant information into an Access Table from the SQL Database( all working nicely )
Now I need to update the existing Access Tables with Data retrieved from the SQL pass through. I have tried a number of different queries all fussing at me for various reasons. Here is an example of the latest query that will get me what I need. This works if I setup a Sandbox in SQL Server and run it MSSQL Management Studio, but will not work in access
UPDATE JT
SET JT.ContractAmt = SBD.TotalSum
FROM JobTable_TEST AS JT
INNER JOIN (
SELECT Sum( Main.amt ) as TotalSum, Main.job
FROM Main
GROUP BY Main.job
) AS SBD
ON SBD.job = JT.JobNumber
In Access the Above Generates the following error "Syntax error( missing operator) in query expression.
Updating following attempt at using SQL Passthrough to run the update Query.
I updated my Query to do this directly from a Passthrough SQL Statement as suggested and get the following error.
ODBC--call failed.
[Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'TableName'.(#208)
Here is what the pass through query i used looked like.
UPDATE AccessTable
SET AccessTable.amt = SQLResult.Total
FROM TableName AS AccessTable
INNER JOIN ( SELECT SUM( SQLTableA.amt) as Total, SQLTableA.job
FROM SQLTableA
LEFT OUTER JOIN SQLTableB ON (SQLTableA.company = SQLTableB.company)
AND (SQLTableA.job = SQLTableB.job)
GROUP BY SQLTableA.job
) AS SQLResult
ON SQLResult.job = AccessTable.JobNum
hopefully that better describes where my tables are located and how my update needs to happen, and maybe someone can point out how this is wrong or if it will even work this way.
Any suggestions would be greatly appreciated
It appears your subquery, aliased as SBD, is missing a job_no column. Therefore you aren't going to be able to join on it.

Ignore denied columns in "select * from"

I need to restrict an (support) user from viewing columns in a table (other users should have full access to this table).
So I granted access to only the columns I specified via "GRANT SELECT ON dbo.TestTable (FirstCol, SecondCol, ThirdCol) TO HR_Intern;"
But when I am running a "SELECT * FROM dbo.TestTable;" i got an Access Denied Error for every other column in the table.
The user is doing customer support using the MSSQL Management Studio directly on the database and the errors won't allow the user to edit the data.
Is it possible to just display the columns the user have access to and ignoring every denied column?
Thanks for your help :)
Better to create a VIEW and provide the users access to it. In the VIEW only those columns these users can see should be part of SELECT statement.
As pointed out by others, you need to replace * by an explicit select list.
In case you are worried about having to specify things twice, here is a query to retrieve the list of permitted columns from metadata.
If you like, you can use its result set to generate (part of) the select list for the query on TestTable.
SELECT c.name
FROM sys.columns c
INNER JOIN sys.database_permissions p
ON p.class = 1
AND p.major_id = c.object_id
AND p.minor_id = c.column_id
AND p.state = 'G'
AND p.grantee_principal_id = DATABASE_PRINCIPAL_ID('HR_Intern')
WHERE c.object_id = OBJECT_ID('dbo.TestTable')
Replace DATABASE_PRINCIPAL_ID('HR_Intern') by DATABASE_PRINCIPAL_ID() to get metadata for the currently active user.
The query is still pretty crude; it disregards table-wide grants, and all denies. You may want to experiment with that a bit.
No. That is how security works in SQL. Basically "SELECT *" is not good form, one is supposed to provide a field list.
If the result set would magically change based on the user logged in that would result in a lot of crappy bug reports because applications would suddenly not work. You asked for all fields, that can not be sent, hence an error report.
One workaround is to have a view with a limited number of fields and direct this user to use the views. Obviously that costs time and attention during development.

SQL Query from SQL novice

I am trying to generate several spreadsheets, sourcing the data from an SQL database. I am new to SQL. The only tool I have for accessing the database is MS Query.
I have managed a lot by the copy & modify process, but now am stuck. I have the following code which allows me to select values from a specified Ac for a specified period.
SELECT Table1.Date, Table1.Ac, Table1.Ref, Table1.Text, Table1.Value
FROM Main.dbo.Table1 Table1
WHERE (Table1.Ac=?) AND (Table1.Date>=? And Table1.Date<=?)
ORDER BY Table1.Date
What I now want to do is:
Delete the Table1.Ac criterium so that I get all records between selected dates
Group by the Table1.Ac field, sorted ascending
In a new column, Display the sum of all the values for each Table1.Ac
This would be very similar to a Summary TB in accounts parlance
As soon as I start modifying the code, I get the message: Parameters are not allowed in queries that can't be displayed graphically.
I would appreciate any help on the SQL code, and on any better tools that I can integrate into Excel. The company is standardising on SQL and converting all its old databases (Access, Accounts, Btrieve, etc) into SQL
I'd recommend working in SQL Server Management Studio if using Microsoft SQL Server.
Does this query suffice?
SELECT Table1.Ac, Sum(Table1.Value)
FROM Main.dbo.Table1 Table1
WHERE (Table1.Date>=? And Table1.Date<=?)
ORDER BY Table1.Date GROUP BY Table1.Ac
Here's a link outlining using MS Query to get data into Excel..
http://office.microsoft.com/en-gb/excel-help/use-microsoft-query-to-retrieve-external-data-HA010099664.aspx

Need to query SSRS database for report access

I would like to know if there is a way to return in a SQL (2005) query (for all reports):
Report ID, Report Name, Report Path, User and Group Security, Datasources.
I know that I can go to my report server page and go to Properties > Security, but we have over 120 reports and I want to see if there is an easier way to get the information I need.
Thanks in advance!
A. Never ever query RS Database directly until you know what are you doing. The queries could acquires lock which could affect overall performance of RS.
B. To know about report execution stats, you can use ExecutionLog view in RS 2008 onwards or following query with NOLOCK Hint.
Select CAST(C.Name AS VARCHAR(20)) [Name],
E.ReportID,
E.InstanceName,
E.UserName,
E.RequestType,
E.Format,
E.Parameters,
E.TimeStart,
E.TimeEnd,
E.TimeDataRetrieval,
E.TimeProcessing,
E.TimeRendering,
E.Source,
E.Status,
E.ByteCount,
E.[RowCount]
from executionlog E WITH (NOLOCK) inner join catalog C WITH (NOLOCK)
on E.ReportID = C.ItemID
C. RS exposes almost all the functionality via SOAP APIs. For example this sample published my MS shows how to get security information on Report Items http://msftrsprodsamples.codeplex.com/wikipage?title=SS2008R2%21RSPermissions%20Sample%20Application&referringTitle=Home
To know more about RS SOAP APIs please see http://msdn.microsoft.com/en-us/library/ms154052.aspx
You can query the ReportServer database directly using something like SSMS. Most of what you're looking for can be found directly in the dbo.Catalog table:
SELECT *
FROM dbo.Catalog
WHERE Type = 2; -- 2 = Reports, 5 = Data Sources