sql-server-2005

Dynamic query construction looping conditions from a XML?

寵の児 提交于 2019-12-22 12:13:40
问题 I need to construct a part of the conditions of my sql query from a xml. I have a XML like: <ROOT> <PARAMETROS> <USU_LOGIN>yleon</USU_LOGIN> <USU_NOMBREPRIMERO>Yerusha</USU_NOMBREPRIMERO> <USU_APELLIDOPRIMERO>Leon</USU_APELLIDOPRIMERO> <USU_EMAIL>yleon@email.com</USU_EMAIL> <USU_FECHACREACION>20130510</USU_FECHACREACION> <USU_CODICIONES1 TIPO="MC">AND USU_ID=4</USU_CODICIONES1> <USU_CODICIONES2 TIPO="MC">AND USU_ID=5</USU_CODICIONES2> <USU_CODICIONES3 TIPO="HG">AND USU_ID=9</USU_CODICIONES3>

Stored Procedure Timing out.. Drop, then Create and it's up again?

↘锁芯ラ 提交于 2019-12-22 11:35:55
问题 I have a web-service that calls a stored procedure from a MS-SQL2005 DB. My Web-Service was timing out on a call to one of the stored procedures I have (this has been in production for a couple of months with no timeouts), so I tried running the query in Query Analyzer which also timed out. I decided to drop and recreate the stored procedure with no changes to the code and it started performing again.. Questions: Would this typically be an error in the TSQL of my Stored Procedure? -Or- Has

SQL Server CTE hierarchy?

£可爱£侵袭症+ 提交于 2019-12-22 11:28:24
问题 I have a table which has hierarchy in it. Lets start with Id = 5 ; this is the child. (a given start parameter - from user) Algorithm: give me the first value which you have encountered for id = 5 if you haven't found value for id = 5 , go to its parent and give me his id if this parent also doesn't have a value - go to its parent ... etc (until parent has no parent - parentId = 0 ) p.s. the result here should be 7. if 7 value was empty so : 9 end if 9 was also empty so : 1 I'm trying to do

Determine SQL Server version of linked server

岁酱吖の 提交于 2019-12-22 11:28:14
问题 Does anyone here know how i can determine the version of SQL running on my linked server through use of TSQL statements? I am running SQL2005 my linked servers are running a mix of sql2000, 2005 and 2008. 回答1: select * from openquery(MyLinkedServer,'SELECT SERVERPROPERTY(''productversion'')') Works 回答2: One minor nitpick about OPENQUERY is that one cannot use anything other than string literals for both the server and the query. With EXEC AT you can at least use varchar variables for the

Efficiency of checking for null varbinary(max) column?

删除回忆录丶 提交于 2019-12-22 11:05:19
问题 Using SQL Server 2008. Example table : CREATE table dbo.blobtest (id int primary key not null, name nvarchar(200) not null, data varbinary(max) null) Example query : select id, name, cast((case when data is null then 0 else 1 end) as bit) as DataExists from dbo.blobtest Now, the query needs to return a "DataExists" column, that returns 0 if the blob is null, else 1. This all works fine, but I'm wondering how efficient it is. i.e. does SQL server need to read in the whole blob to its memory,

Cell to Cell comparison in Sql Server?

十年热恋 提交于 2019-12-22 10:58:30
问题 I have tbl1 : Id | c1 | c2 | c3 | ____|_____|______|_______|_ 1 a b c ____|_____|______|_______|_ 2 h j k ____|_____|______|_______|_ 3 t y u ____|_____|______|_______|_ I have tbl2 : Id | c1 | c2 | c3 | ____|_____|______|_______|_ 1 a b D ____|_____|______|_______|_ 2 c c c ____|_____|______|_______|_ 3 k l k ____|_____|______|_______|_ I need to compare each cell from tbl1 to its appropriate place in tbl2 : the desired output is : Id |tbl1 | tbl2 | ____|_____|______| 1 a a ____|_____|______

Datatype to save excel file in sql server?

倖福魔咒の 提交于 2019-12-22 10:45:13
问题 I have a table in which there are two columns : 1. import type, 2. Excel import template. The second column - "Excel import template" should store the whole excel file. How would I save excel file in databse...can I use binary datatype column, convert excel file to bytes and save the same ? Thanks in advance ! 回答1: Yes, you can use a binary file type. VARBINARY(MAX) is likely to fit the purpose best. Regarding how to "convert the Excel file to bytes" (it really is bytes from the beginning),

SQL NOT IN Clause

偶尔善良 提交于 2019-12-22 09:50:16
问题 I have a query which is not working as expected Q1: SELECT id, name FROM vw_x WHERE id NOT IN (select pid from table_x) GROUP BY id, name Having max(c_date) > GETDATE() Q2: SELECT id, name FROM vw_x GROUP BY id, name Having max(c_date) > GETDATE() Q1 is not returning anything even though i know those ids are not in table_x Q2 runs correctly without NOT IN What could be wrong with my query? 回答1: you have a NULL value in the table try this SELECT id, name FROM vw_x WHERE id NOT IN (select pid

SQL query ; horizontal to vertical

回眸只為那壹抹淺笑 提交于 2019-12-22 08:57:22
问题 I'm stuck with a SQL query (SQL Server) that involves converting horizontal rows to vertical rows Below is my data No Flag_1 Flag_2 Flag_3 --- ---- ----- ----- A 1 2 3 B 4 1 6 After conversion , the table should be No FlagsName Flag_value -- ---- ---------- A Flag_1 1 A Flag_2 2 A Flag_3 3 B Flag_1 4 B Flag_2 1 B Flag_3 6 Any input on this would be helpful? I'm trying to play around ROW_NUMBER over partition. but it is not working somehow !!! Thanks !!! 回答1: You can use a UNION ALL : select

How to abort an insert of multiple rows in a trigger

允我心安 提交于 2019-12-22 08:49:55
问题 With sql Server 2005. I have declared a trigger that get fired "AFTER INSERT, UPDATE" , in this trigger I'm using a WHILE and a CURSOR to loop on the INSERTED table's rows. When I find a row that does not sotisfy a specific condition: I want the trigger to rise an error and do not insert any of the rows that fired the trigger (not even those that already satisfaied my condition). <--- I don't know how to do this! Can you tell me how can I rise the error and prevent the insertion? 回答1: use