Helpful blog post by rule30: CRM 2011 – Find "Unused" Custom Fields via SQL.
And to get this to work in CRM 4.0, just replace the “SystemFormBase” table name with “OrganizationUIBase.” Microsoft changed the name of that table in CRM 2011.
Helpful blog post by rule30: CRM 2011 – Find "Unused" Custom Fields via SQL.
And to get this to work in CRM 4.0, just replace the “SystemFormBase” table name with “OrganizationUIBase.” Microsoft changed the name of that table in CRM 2011.
This code snippet works beautifully. Just replace the table/field names like so:
Run and done:
with cte as
(
select
Accountid,
name,
parentid,
cast(row_number()over(partition by parentid order by name) as varchar(max)) as [path]
from @tbl_accounts
where parentid = 0
union all
select
t.AccountID,
t.name,
t.ParentID,
[path] + cast(row_number()over(partition by t.parentid order by t.name) as varchar(max))
from
30. cte
join @tbl_accounts t on cte.AccountID = t.ParentID
)
select
Accountid,
name,
ParentID,
[path]
from cte
order by path
Thanks, Kev Riley!
If you try to restore a database from a backup and get the error “Exclusive access could not be obtained because the database is in use” then here are some things to try.
http://www.codeproject.com/Articles/315538/Exclusive-access-could-not-be-obtained-because-the
Personally, taking the database offline and then online again worked for me today.
To fix this issue, copy files from C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\SQLDB\Extensions\SqlServer\110\SQLSchemas to the path that VS is using to look for it.
I love this little tip because I prefer to edit a sql db table through the GUI if possible. (I know, I know. Leave me alone.)
Pedro’s answer is short and sweet:
Go into Tools -> Options -> Designers-> Uncheck “Prevent saving changes that require table re-creation”. Voila.
That happens because sometimes it is necessary to drop and recreate a table in order to change something. This can take a while, since all data must be copied to a temp table and then re-inserted in the new table. Since SQL Server by default doesn’t trust you, you need to say “OK, I know what I’m doing, now let me do my work.”
When your table has lots of columns that need to be broken out into separate records…
It can be done with a single SELECT statement!
Needless to say, when I found this little gem of a sql statement, I was super excited.
When you have a table structured like this:
UserID | UserName | AnswerToQuestion1 | AnswerToQuestion2 | AnswerToQuestion31 | John | 1 | 0 | 12 | Mary | 1 | 1 | 0
And you want to get a result set like this (split the three data columns into three separate rows):
UserID | UserName | QuestionName | Response1 | John | AnswerToQuestion1 | 11 | John | AnswerToQuestion2 | 01 | John | AnswerToQuestion3 | 12 | Mary | AnswerToQuestion1 | 12 | Mary | AnswerToQuestion2 | 12 | Mary | AnswerToQuestion3 | 0
Use this:
SELECT
Y.UserID,
Y.UserName,
QuestionName = ‘AnswerToQuestion’ + X.Which,
Response =
CASE X.Which
WHEN ‘1’ THEN AnswerToQuestion1
WHEN ‘2’ THEN AnswerToQuestion2
WHEN ‘3’ THEN AnswerToQuestion3
END
FROM YourTable Y
CROSS JOIN (SELECT ‘1’ UNION ALL SELECT ‘2’ UNION ALL SELECT ‘3’) X (Which)
http://stackoverflow.com/questions/3678479/split-multiple-columns-into-multip…
(Yes, I realize this table is still not completely normalized, but it’s a step in the right direction.)
Also, a related sql query: if you have a bunch of values in a single column that you need to break out into multiple rows: http://www.sqlteam.com/article/parsing-csv-values-into-multiple-rows
So simple, so useful, so should’ve been using this awhile:
select @var1 = avg(someColumn), @var2 = avg(otherColumn) from theTable
This article saved me today. I’d been trying to figure out how to make my query run faster for days.
After going through this article, my query went from a minute to less than a second.
Thanks, Maresa!!!
http://www.microshell.com/database/sql/optimizing-sql-that-selects-the-maxmin…