|
Im feeling very stupid today. for some reason im always getting errors. copy, paste and try the below code. It parses ok but when Execute im getting this error ------- "The data types varchar and xml are incompatible in the add operator."
########################################
ALTER PROC [dbo].[sp_Testing2]
@empdata xml,
@code varchar
AS
DECLARE @hDoc int
declare @somethingToAdd xml
exec sp_xml_preparedocument @hDoc OUTPUT,@empdata
set @somethingToAdd = '<Employee ID= ''101''><Code>'+@code+'</Code><Name>''Name101''</Name></Employee>'
Select @empdata
set @empdata.modify('insert sql:variable('+ @somethingToAdd+') into (/Employees)[1]')
-- return the XMl
Select @empdata
####################################################
|
|
|
|
|
One problem is that you modified the insert literal (don't concatenate!).
If you don't need hDoc in somewhere else, the procedure would be in minimum something like this (note that @code is xml):
ALTER PROC [dbo].[sp_Testing2]
@empdata xml,
@code xml
AS
Select @empdata
set @empdata.modify('insert sql:variable("@code") into (/Employees)[1]')
-- return the XMl
Select @empdata
The need to optimize rises from a bad design
|
|
|
|
|
Thanks you have helped alot
|
|
|
|
|
You're welcome
The need to optimize rises from a bad design
|
|
|
|
|
hi,
i am not very much sure that sql server database can be installed on windows xp os or not. whenever i am trying to install sql server database on windows xp os then information is showing that only client can be installed but database portion is disabled........so if anyone know that how to install sql server database on windows XP OS then plzz let me know with in detail info.
Thanks
tbhattacharjee
|
|
|
|
|
Yes it can be installed on XP, but SP level must be 2.
Depending on the version, you must first install client components and after that server portion. Also you must have sufficient privileges.
The need to optimize rises from a bad design
|
|
|
|
|
Please help me,
I want to connect to an mdf database (built by SQL Server 2005 Express) in VC++ using OLE DB. I can't do it. please help. please provide a code for me to connect to "c:\Database#1.mdf" using code.
Please help. Urgent.
|
|
|
|
|
|
yeah, no one cares if it urgent for you. Connection strings are one of the basic parts of programming. At least TRY to do it and if you get an error come back and we can look at your code. We're not going to do your work for you.
Blog link to be reinstated at a later date.
|
|
|
|
|
This is my code:
<br />
_ConnectionPtr m_pConnection;<br />
<br />
CoInitialize(NULL);<br />
<br />
m_csDataSource = <br />
"Provider=SQLNCLI;Server=.\\SQLExpress; \<br />
AttachDbFilename=C:\\DATABASE#1.MDF; \<br />
Trusted_Connection=Yes;"<br />
<br />
<br />
<br />
HRESULT hRes = m_pConnection.CreateInstance(__uuidof(Connection));<br />
if (SUCCEEDED(hRes))<br />
{<br />
hRes = m_pConnection->Open(_bstr_t((LPCTSTR)m_csDataSource),<br />
_bstr_t(L""),_bstr_t(L""),adModeUnknown);<br />
if (SUCCEEDED(hRes))<br />
{<br />
m_bIsConnectionOpen = TRUE;<br />
}<br />
}<br />
I get this error:
An attempt to attach an auto-named database for file C:\\Database#1.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located in on UNC share.
|
|
|
|
|
Why do I bother.
Blog link to be reinstated at a later date.
|
|
|
|
|
My Paranoid Hubby wrote: Why do I bother.
For the entertainment of others
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Hi,
I can add two different columns to an index. What is the difference if I make two separate indexes for two columns instead of creating one index and adding two columns to it.
Thanks
_
|
|
|
|
|
This depends very much on the database you are using (SQL Server, Oracle, MySQL etc).
But basically if you create two separate indexes, they can be used independently. When you have one index, the tree traversal must use the first column even though you are not referring to it in a query. Think of it like an index in a book. If you have two levels on chapters like:
- 1.1
- 1.2
- 1.3...
- 2.1
- 2.2
- 2.3...
and you want to find all chapters that are numbered ???.3 you must scan through the whole index to find what you are looking for.
Disclaimer: The description is really simplified and is not accurate for all databases so the situation is actually much more complex. But this should give you the idea.
Hope this helps,
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Thanks for your response. To be more specific, I'm talking about SQL Server database. Suppose that I've got a query like this:
select id, fname, lname, age from customers where lname = @lname order by age asc
Besides having a default clustered index on id column, I can have an index containing two columns, lname and age . But I can also have an index for lname and an index for age column separately. Does it matter which one is better in this case?
I may also have another query like this:
select id, lname from customers order by age asc
for the sake of this query, according to what I learned from your explanation, having an index containing only age column would be better than an index containing lname and age . right?
Can I have both of aforementioned indexes together? Will SQL Server determine which index is better to use based on my query?
Thanks for your help
_
|
|
|
|
|
Having both indexes (lname, age and age) is ok. However this will have some performance penalty for insert , update and delete statements.
You could try having only lname + age or lname and age separately. The optimizer will pick up the index / indexes it will consider most benefitial. You can verify optimizer behaviour using execution plan.
If you have only lname + age , it is possible that the optimizer makes horizontal scan on the index tree for the second query.
If you have lname and age separately, the optimizer can choose to make an index join for the first query.
So try all variations and use execution plan to see what is reasonable in your case (especially consider that those are hardly the only queries, so you should consider all query needs for this table if possible).
It's like playing chess
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Yea it's like playing a chess!
From what I've seen in execution plan, it tells me that how much percent of time has been spent on which phase of query. Do you have any recommendation for me on how to make best use of execution plan to fine tune my indexes? I'm sorry if this question is very general and might bother you.
Thanks again
_
|
|
|
|
|
I found an article here: Execution Plans[^]
I think it can help me a lot.
Thanks again for your help
_
|
|
|
|
|
Just noticed your message.
That article is a good one. Especially concentrate on the total cost (= estimated seconds) and how it's distributed. Then observe logical I/O amounts (don't mind so much about physical I/O).
Your question is not bothering me at all. Actually this area is one of my special interests
Happy coding!
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Hello,
I have one datetime column named Hours in SQL Server Table1, which gives the output as 09/26/2008 01:00:00, 09/26/2008 02:00:00, 09/26/2008 03:00:00 till 09/26/2008 12:00:00 format.
I wanted to get just the year in int datatype from this format and I got it using (SELECT CONVERT(int, YEAR (Hours)) AS Year FROM Table1) and I am getting the correct Year as I wanted 2008. Same way I am getting month and date also. But the issue is with hour.
I want the hour also in the integer format. I mean if there is 01:00:00, then the output should just be 1 and same way the next should be 2.
Can anyone please help me to achieve this output?
I want a proper syntax for the same.
Meanwhile I will carry on the research on my part.
Thank you.
|
|
|
|
|
|
try this
<br />
select CAST(DATEDIFF(minute, 0, '01:00:00') AS int) / 60
Hope it will help.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Hi
My Stored Procedure output is as below given.
Interval Avg1 Avg2
NULL NULL NULL
04/08 NULL NULL
05/08 2000 NULL
NULL 1000 NULL
NULL NULL NULL
NULL NULL 4000
NULL NULL 3000
I want result in two rows as below given.
Interval Avg1 Avg2
04/2008 2000 4000
05/2008 1000 3000
Please let me know how i can do this using temm table ?
Thanks
Care Career
|
|
|
|
|
Based on the info you posted, the only thing I can imagine is that you should modify the output from sp to give you what want.
So, you need to include to the post, how the result is made in sp and what do you want to change
or
if you cannot change the sp, what is the logic you want to achieve with temp tables (why 04/2008 has 4000 in avg2, since there is nothing in the data combining the row "NULL NULL 4000" to the row "04/08 NULL NULL"
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Hi
I do not want to change my existing SP I just want output as below given.I want to remove NULL Please help..
Sr No Interval Avg1 Avg2
1 04/2008 2000 4000
2 05/2008 1000 3000
|
|
|
|