SQL Server 2000 SP3a
Im using a sproc to make a sql statement. The statement is built up and
assigned to @.SQL1 nvarchar(4000), then at the end of the sproc its runs:
exec sp_executesql @.SQL1
The problem is that I've reached the 4000 limit!! How do other people get
round this, bearing in mind that its full of inner joins with sub selects, s
o
I dont think I can split it out. And because the sproc can create a view
which is updateable, I can't turn those sub selects into views as this makes
the newly created view non-updateable.
How can I build up a SQL string that is bigger than 4000 please.Split it up into multiple char/varchar variables and do:
EXEC( @.var1 + @.var2 + ...+ @.varn )
Anith|||Off the top of my head, can you incrementally build this using temp
tables and/or table variables?
Maybe something like...
procedure MyProc
as
-- do something with #temp1
-- do something with #temp2
select * from #temp1
join #temp1 on #temp2.something = #temp1.something
go
Just a thought.
Bryce|||If that means I can link several statements, which each on their own don't
make sense, together and execute in one go that would be perfect!!!
I won't be able to check til Monday, so many thanks in advance, I was
getting REALLY worried that many hours of trying to get get a one sproc does
all approach was going to fall at the last hurdle.
I shall read some more on exec / sp_executesql as it sounds like more can be
done than I had assumed.
Many thanks!
"Anith Sen" wrote:
> Split it up into multiple char/varchar variables and do:
> EXEC( @.var1 + @.var2 + ...+ @.varn )
> --
> Anith
>
>
Showing posts with label nvarchar. Show all posts
Showing posts with label nvarchar. Show all posts
Wednesday, March 21, 2012
Tuesday, March 20, 2012
Re sort
Hi all
I Have Table Num As Int , Name As NvarChar(20) I Need Trigger to Resort The
Field Num When I Change The num
Num Name
1 aaaaa
2 bbbbb
3 cccccc
4 ddddd
I Want when I Change the Num 1 To 2 Came Like
Num Name
1 bbbbb
2 aaaaaa
3 cccccc
4 ddddd
Re sort The Num In Trigger
Thankswhat are you talking about? Sorting is done at query time, by specifying a
sort order.
"Taha" <taha105@.hotmail.com> wrote in message
news:%23%23nlsb9jGHA.4512@.TK2MSFTNGP04.phx.gbl...
> Hi all
>
> I Have Table Num As Int , Name As NvarChar(20) I Need Trigger to Resort
> The Field Num When I Change The num
>
> Num Name
> 1 aaaaa
> 2 bbbbb
> 3 cccccc
> 4 ddddd
>
> I Want when I Change the Num 1 To 2 Came Like
>
> Num Name
> 1 bbbbb
> 2 aaaaaa
> 3 cccccc
> 4 ddddd
>
> Re sort The Num In Trigger
>
> Thanks
>|||Let's make this problem more concrete. You want to put automobiles
into numbered parking spaces and move them around.
CREATE TABLE Motorpool
(parking_space INTEGER NOT NULL PRIMARY KEY
CHECK (parking_space > 0),
vin CHAR(170) NOT NULL);
Re-arrange the display order based on the parking_space column:
CREATE PROCEDURE SwapVehicles (@.old_parking_space INTEGER,
@.new_parking_space INTEGER)
AS
UPDATE Motorpool
SET parking_space
= CASE parking_space
WHEN @.old_parking_space
THEN @.new_parking_space
ELSE parking_space + SIGN(@.old_parking_space - @.new_pos)
END
WHERE parking_space BETWEEN @.old_parking_space AND @.new_parking_space
OR parking_space BETWEEN @.new_parking_space AND @.old_parking_space;
When you want to drop a few rows, remember to close the gaps with this:
CREATE PROCEDURE CloseMotorpoolGaps()
AS
UPDATE Motorpool
SET parking_space
= (SELECT COUNT (M1.parking_space)
FROM Motorpool AS M1
WHERE M1.parking_space <= Motorpool.parking_space);|||Thank you CELKO
"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1150310619.762497.25420@.p79g2000cwp.googlegroups.com...
> Let's make this problem more concrete. You want to put automobiles
> into numbered parking spaces and move them around.
> CREATE TABLE Motorpool
> (parking_space INTEGER NOT NULL PRIMARY KEY
> CHECK (parking_space > 0),
> vin CHAR(170) NOT NULL);
> Re-arrange the display order based on the parking_space column:
> CREATE PROCEDURE SwapVehicles (@.old_parking_space INTEGER,
> @.new_parking_space INTEGER)
> AS
> UPDATE Motorpool
> SET parking_space
> = CASE parking_space
> WHEN @.old_parking_space
> THEN @.new_parking_space
> ELSE parking_space + SIGN(@.old_parking_space - @.new_pos)
> END
> WHERE parking_space BETWEEN @.old_parking_space AND @.new_parking_space
> OR parking_space BETWEEN @.new_parking_space AND @.old_parking_space;
> When you want to drop a few rows, remember to close the gaps with this:
> CREATE PROCEDURE CloseMotorpoolGaps()
> AS
> UPDATE Motorpool
> SET parking_space
> = (SELECT COUNT (M1.parking_space)
> FROM Motorpool AS M1
> WHERE M1.parking_space <= Motorpool.parking_space);
>
I Have Table Num As Int , Name As NvarChar(20) I Need Trigger to Resort The
Field Num When I Change The num
Num Name
1 aaaaa
2 bbbbb
3 cccccc
4 ddddd
I Want when I Change the Num 1 To 2 Came Like
Num Name
1 bbbbb
2 aaaaaa
3 cccccc
4 ddddd
Re sort The Num In Trigger
Thankswhat are you talking about? Sorting is done at query time, by specifying a
sort order.
"Taha" <taha105@.hotmail.com> wrote in message
news:%23%23nlsb9jGHA.4512@.TK2MSFTNGP04.phx.gbl...
> Hi all
>
> I Have Table Num As Int , Name As NvarChar(20) I Need Trigger to Resort
> The Field Num When I Change The num
>
> Num Name
> 1 aaaaa
> 2 bbbbb
> 3 cccccc
> 4 ddddd
>
> I Want when I Change the Num 1 To 2 Came Like
>
> Num Name
> 1 bbbbb
> 2 aaaaaa
> 3 cccccc
> 4 ddddd
>
> Re sort The Num In Trigger
>
> Thanks
>|||Let's make this problem more concrete. You want to put automobiles
into numbered parking spaces and move them around.
CREATE TABLE Motorpool
(parking_space INTEGER NOT NULL PRIMARY KEY
CHECK (parking_space > 0),
vin CHAR(170) NOT NULL);
Re-arrange the display order based on the parking_space column:
CREATE PROCEDURE SwapVehicles (@.old_parking_space INTEGER,
@.new_parking_space INTEGER)
AS
UPDATE Motorpool
SET parking_space
= CASE parking_space
WHEN @.old_parking_space
THEN @.new_parking_space
ELSE parking_space + SIGN(@.old_parking_space - @.new_pos)
END
WHERE parking_space BETWEEN @.old_parking_space AND @.new_parking_space
OR parking_space BETWEEN @.new_parking_space AND @.old_parking_space;
When you want to drop a few rows, remember to close the gaps with this:
CREATE PROCEDURE CloseMotorpoolGaps()
AS
UPDATE Motorpool
SET parking_space
= (SELECT COUNT (M1.parking_space)
FROM Motorpool AS M1
WHERE M1.parking_space <= Motorpool.parking_space);|||Thank you CELKO
"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1150310619.762497.25420@.p79g2000cwp.googlegroups.com...
> Let's make this problem more concrete. You want to put automobiles
> into numbered parking spaces and move them around.
> CREATE TABLE Motorpool
> (parking_space INTEGER NOT NULL PRIMARY KEY
> CHECK (parking_space > 0),
> vin CHAR(170) NOT NULL);
> Re-arrange the display order based on the parking_space column:
> CREATE PROCEDURE SwapVehicles (@.old_parking_space INTEGER,
> @.new_parking_space INTEGER)
> AS
> UPDATE Motorpool
> SET parking_space
> = CASE parking_space
> WHEN @.old_parking_space
> THEN @.new_parking_space
> ELSE parking_space + SIGN(@.old_parking_space - @.new_pos)
> END
> WHERE parking_space BETWEEN @.old_parking_space AND @.new_parking_space
> OR parking_space BETWEEN @.new_parking_space AND @.old_parking_space;
> When you want to drop a few rows, remember to close the gaps with this:
> CREATE PROCEDURE CloseMotorpoolGaps()
> AS
> UPDATE Motorpool
> SET parking_space
> = (SELECT COUNT (M1.parking_space)
> FROM Motorpool AS M1
> WHERE M1.parking_space <= Motorpool.parking_space);
>
Subscribe to:
Posts (Atom)