|
|
Hi!
Sorry, I don't think that your query will work. You cannot insert into a table variable from inside a dynamic query. Try the following:
declare @test table ( MyId int )
insert into @test values (5)
declare @stmt varchar(128)
set @stmt = 'insert into @test values (6)'
exec( @stmt )
The dynamically executed statment will not work because it does not know about the table var @test.
Additionally I saw that you forgot the ( ) in your exec-statement. exec @querystring cannot execute a dynamic query; you have to write exec ( @querystring ) . Otherwise SQL Server will think you want to execute a stored procedure with the name stored in @querystring. See Transact-SQL-Reference for EXECUTE in Books Online for details.
Regards,
Rainer.
Rainer Stropek
Visit my blog at http://www.cubido.at/rainers
|
|
|
|
|
I have an problem in sequel query. i.e I have 2 table where master child relationship exits
Table1 CorrespondentCodePK, ContactCode,PartNo,
the data in Table1 is 1,1,1
2,1,1
3,1,2
Table2 CorrespondentCodeFK,PartNo,PartName,
the data in Table2 is 1,1,Part1
1,1,Part2
2,1,Part1
and I want the result in the bellow mentioned format i.e
CorrespondentCodePK,ContactCode,PartName (i.e all part names for the CorrespondentCodePK should come in PartName column as a one record)
1,1,Part1Part2
2,1,Part1
|
|
|
|
|
First, make a function:
NOTE: The lengths of the varchar variables will depend upon your data.
CREATE FUNCTION GetPartNames (@nCorrCode int)
RETURNS varchar(1000) AS
BEGIN
DECLARE @cPartNames varchar(1000)
DECLARE @cPartName varchar(50)
SELECT @cPartNames = ''
DECLARE partcursor CURSOR FOR
SELECT DISTINCT PartName
FROM table2
WHERE correspondentcodefk = @nCorrCode
OPEN partcursor
FETCH NEXT FROM partcursor INTO @cPartName
WHILE @@FETCH_STATUS = 0
BEGIN
select @cPartNames = @cPartNames + @cPartName
FETCH NEXT FROM partcursor INTO @cPartName
END
CLOSE partcursor
DEALLOCATE partcursor
RETURN(@cPartNames)
END
Next, use this SQL:
SELECT correspondentcodepk, contactcode, dbo.GetPartNames(correspondentcodepk) AS PartNames FROM table1
----------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
If you have SQL 2005 you could also write a short user-defined aggregation function in C# that concats strings.
Regard,
Rainer.
Rainer Stropek
Visit my blog at http://www.cubido.at/rainers
|
|
|
|
|
hi i have a question about the possibility of joining 2 database tables that are on different servers in different countries, there are 2 tables that need to be stored in one location as the information changes and is updated everyday this location is seperate from the rest of the database tables that store specific company information and must be on the companies server.so i guess my question is can this be done and how to go about joining the tables
any ideas, advice as im new to development or help would be appreciated thanks in advance
Tim
|
|
|
|
|
|
How can I send data from MSSQL to HTML ? Suggestions Please.
|
|
|
|
|
|
Reply to me if solution is helpful to you.
In Sqlserver 2000
1. Goto the menu click "query" tab.
2. select "Results to file " option.
3. Execute the query F5.
4. It will prompt the window to save the file .Save the file as ".html" extension.
5. Your requirement is fullfilled.(note -->The result is not in order/linear in order).
vivek
|
|
|
|
|
Thank you Vivek for your answer but, I wanted it specifically configured in HTML format with HTML tags and sp_CreateWebTask can very well do that.
|
|
|
|
|
why " setcount on" is used in stored procedures ?
what does it actually means ?
vivek
|
|
|
|
|
used to display the "messages" return by running a sql statement. Experiment with it in Query Analyzer to see what it does to a basic SQL statement.
Look where you want to go not where you don't want to crash.
Bikers Bible
|
|
|
|
|
Hi,
I hope that there is no option such as setcount on in sql, Instead we have a statement set nocount on/Off
The explanation is given below which is available in SQL books online please refer the same for further explanation
<definition from="" books="" online="">
Stops the message indicating the number of rows affected by a Transact-SQL statement from being returned as part of the results.
Syntax
SET NOCOUNT { ON | OFF }
Remarks
When SET NOCOUNT is ON, the count (indicating the number of rows affected by a Transact-SQL statement) is not returned. When SET NOCOUNT is OFF, the count is returned.
The @@ROWCOUNT function is updated even when SET NOCOUNT is ON.
SET NOCOUNT ON eliminates the sending of DONE_IN_PROC messages to the client for each statement in a stored procedure. When using the utilities provided with Microsoft® SQL Server™ to execute queries, the results prevent "nn rows affected" from being displayed at the end Transact-SQL statements such as SELECT, INSERT, UPDATE, and DELETE.
For stored procedures that contain several statements that do not return much actual data, this can provide a significant performance boost because network traffic is greatly reduced.
The setting of SET NOCOUNT is set at execute or run time and not at parse time.
Happy Programming
|
|
|
|
|
How I write the condition of SQL statement to retrieve all author's name from database pubs if passing parameter is null and if user insert an author's name, then only particular name will be display..
thanks
angela
|
|
|
|
|
CREATE PROCEDURE GetAuthors
@AuthorName nvarchar(100)
AS
IF @AuthorName IS NULL
SELECT AuthorName FROM Author
ELSE
SELECT AuthorName FROM Author WHERE AuthorName=@AuthorName
Is that one?
|
|
|
|
|
when i run your SQL statement, it not return any value if i didn't insert author's name.
I get another SQL statement that can solve my problem,
Declare @au_lname char(30)
Select @au_lname = ''
select title, price,
Name = substring (au_lname, 1,40), type
from titleauthor ta JOIN authors a on ta.au_id = a.au_id
JOIN titles t on ta.title_id = t.title_id
Where 1 =
Case
When RTRIM(@au_lname) = '' Then 1
When RTRIM(@au_lname) <> '' And
RTRIM(UPPER(@au_lname)) = RTRIM(UPPER(au_lname)) Then 1
Else 0
End
it's cool;)
angela
|
|
|
|
|
Hi!
You can simplify this statement:
Declare @au_lname char(30)
Select @au_lname = ''
select title, price, Name = substring (au_lname, 1,40), type
from titleauthor ta
JOIN authors a on ta.au_id = a.au_id
JOIN titles t on ta.title_id = t.title_id
where RTRIM(@au_lname) = ''
or RTRIM(UPPER(@au_lname)) = RTRIM(UPPER(au_lname))
Regards,
Rainer.
Rainer Stropek
Visit my blog at http://www.cubido.at/rainers
|
|
|
|
|
ok, thanks for your solution
angela
|
|
|
|
|
Hi
I have a simple web page that written in C# and Asp.Net.
In that page i have asimple insert query that work by
Microsoft Accees .
When I run it in my camputer az a project I don't reciev this message but when i placed on my host or on my iis I reciev this massage .
If You Know How Can I solv this problem plz
answer me az soon az possible:->
Thanks alot .
-- modified at 8:22 Sunday 11th June, 2006
|
|
|
|
|
isiran wrote: When I run it in my camputer az a project I don't reciev this message but when i placed on my host or on my iis I reciev this massage
Sounds like a permissions issue. Make sure the db is in a location where the web user has permissions to write to.
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
-- modified at 2:33 Tuesday 13th June, 2006
|
|
|
|
|
Hi
I checked it befor.
I have write access on my db folder on my camputer an host.
Thansk alto.
|
|
|
|
|
isiran wrote: I checked it
mmmm
isiran wrote: I have write access
Your account and the web user account are differnt, remember that ISS runs with different (even more restricted) permissions than you.
Failing a permissions issue, I have no idea then. The only issues I have expereinced and seen posted on the net have been permissions related.
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
|
isiran wrote: Thanks
Your welcome, its nice to help polite people.
So I take it, the problem was a permissions one?
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|