Viewing 15 posts - 1,321 through 1,335 (of 1,438 total)
Slightly simpler...
select T.Loc.value('../../@Id','uniqueidentifier') AS [Institution]
, t.Loc.value('./Email[1]','varchar(128)') AS [Email]
, t.Loc.value('./BusinessRoleGuid[1]','uniqueidentifier') AS [BusinessRoleGuid]
FROM @x.nodes('/XML/Institution/Users/User') AS T(Loc )
June 17, 2008 at 4:58 pm
Lots of ways of doing this
select a.ID,a.name,b.id as 'other id',b.name as OtherName
from addr a
left outer join addr b on b.id>a.id
and not exists (select * from addr c...
June 17, 2008 at 7:36 am
Assigning the COUNT(*) to a variable will prevent it returning a result set
DECLARE @RowsCount int
SET @RowSql = 'SELECT @RowsCount = COUNT(*) FROM MyTable'
EXEC SP_EXECUTESQL ...
June 17, 2008 at 2:27 am
Try joining to a tables of ranges
CREATE TABLE Ranges
(RangeFrom money NOT NULL,
RangeTo money NOT NULL,
Range varchar(20) NOT NULL,
PRIMARY KEY CLUSTERED (RangeFrom, RangeTo));
INSERT INTO Ranges VALUES (0, 50,...
June 16, 2008 at 9:10 am
The file as saved from Management Studio seems to be ANSI even though the XML indicates it is UTF-16.
One possible solution, open the file in notepad and save as Unicode...
June 12, 2008 at 9:53 am
select r.value('Name[1]','varchar(20)') as name,
r.value('Value[1]','decimal(12,6)') as value
from @x.nodes('/ArrayOfNameValuePair/NameValuePair') as x(r)
June 12, 2008 at 8:38 am
Something like this
declare @x xml
set @x='
... your xml
'
select r.value('local-name(.)','varchar(20)') as name,
r.value('./text()[1]','varchar(20)') as value
from @x.nodes('//*') as x(r)
June 10, 2008 at 2:59 am
Use sp_executesql with output parameters
.
.
.
select @STR='select @count=count(*) from '+@t1+' where unit_no=''352022000637171'';'
execute sp_executesql
@STR,
...
June 4, 2008 at 5:44 am
> You can't create an index on a table variable
But you can do this...
declare @t table(x int not null primary key clustered)
May 30, 2008 at 4:49 am
bull2000 (5/14/2008)
For example,
Table_A has some columns whose length is longer than the ones in Table_B
Is...
May 30, 2008 at 2:45 am
Try this
SELECT CAST((CAST(b.[total shipping days] AS NUMERIC(5,2))/CAST(c.[shipping days] AS NUMERIC(5,2)))AS NUMERIC(5,2)) AS [average working days]
FROM
(SELECT
SUM(DATEDIFF(d,[order date], [ship date])) AS [total shipping days]
FROM orders)b,
(SELECT
COUNT(*) AS [shipping days]
FROM orders...
May 23, 2008 at 5:59 am
I tend to use the "max ... group by" pattern
select [Plan],
max(case when Setting='Colour' then [Value] end) as Colour,
...
May 22, 2008 at 6:55 am
Richard (5/21/2008)
Although it only performs well when there is clustered index over the order by. (the sort kills it when there...
May 21, 2008 at 6:15 am
Use row_number
with cte as (
select id,BusKey,Name,StartDate,EndDate,
row_number() over(partition by BusKey order by EndDate desc,StartDate desc) as rn
from #t)
select id,BusKey,Name,StartDate,EndDate
from cte
where rn=1
May 21, 2008 at 4:53 am
Maybe this?
declare @x xml
set @x='
... your xml
'
select
r.value('Type[1]','VARCHAR(6)') as Type,
r.value('GUID[1]','VARCHAR(25)') as GUID,
r.value('Date[1]','DATETIME') as Date,
r.value('RegisterCode[1]','VARCHAR(6)') as RegisterCode,
r.value('User[1]','BIGINT') as [User],
r.value('StoreUID[1]','VARCHAR(6)') as StoreUID,
r.value('Charges[1]','MONEY') as Charges,
r.value('Taxes[1]','MONEY') as Taxes,
r.value('Tenders[1]','MONEY') as Tenders,
case when r.value('PostVoid[1]','VARCHAR(20)') is not...
May 20, 2008 at 2:40 am
Viewing 15 posts - 1,321 through 1,335 (of 1,438 total)