Showing posts with label dear. Show all posts
Showing posts with label dear. Show all posts

Monday, March 26, 2012

Query with another query input parameter

Dear Friends,

I have a long query with an input parameter. I want this input parameter be all teh values returned from another query.

SELECT DIR FROM DIRECCAO

BIG QUERY with DIR input parameter.

How can I do?

Thanks.

SELECT @.DIR = DIR FROM DIRECCAO

EXEC BIG_QUERY @.DIR

HTH,

Babu

|||

IT WORKS AND THE QUERY IS:

ALTER PROCEDURE [dbo].[GD_SP_FACTURA_GLOBAL]

AS

DECLARE @.DIR nvarchar(10)

SELECT @.DIR = DIR_NOME FROM Direccao

EXECUTE dbo.GD_SP_FACTURA_ValorTotal @.DIR

BUT How can I SUM all the values returned by the BIGQuery?

THANKS!!

|||How can I have the sum and it's possible to return a list of all values returned by the bigQuery? THANKS!!!|||

Could anyone help me?

Thanks!

Wednesday, March 7, 2012

Query to another database

Dear all,

I have views in database that select records from a table in another database in the same server.
Can I set security in such a way for not to give direct access to the table. I know than it is possible if a table and views are in the same database and have the same owner, but I failed to get the same for different databases.

Thanks.

The following thread includes an example of how to achieve this via signed code:

controlling security through stored procedures -- 2005 behaviour


Also, for another option, search for "cross database ownership chaining" in Books Online. There is a server option that enables this. BOL contains information on it.

Thanks
Laurentiu

|||Thank you

Saturday, February 25, 2012

Query that adds data for every user

Dear Masters;

I have a Messages table; I use this table to post System Messages to my users. But what I don't know is how can I add data for multiple users. I mean I want to add same message for multiple users (ex: Please update your infos). In the belove table I have some messages for users 100 and 200; How can I add same (please update your infos) messages to both users?

Ex: Messages Table

ID UserID Msg

1 100 "Hello"

2 100 "Hi"

3 200 "Hello"

Thanks..

try this to add your message to current message

UPDATE Messages
SET msg=msg + ' Please update your infos '
where userID in (100,200)

or this to create new content for message

UPDATE Messages
SET msg = 'Please update your infos '
where userID in (100,200)

Thanks

|||

Thanks for repliying;

But may I write a select statement for example in the in() section?

Cause I may need to add for all users so I gues it should be something like "for" statement.. But if I can write select statement inside in() That may solve...

I'll try thanks

|||

Yes, you can try for example

where userID in (select UserID from messages where userID>100)

but your select statement should return only one column.

Thanks

|||I don't think you want an update statement for this purpose. If you update where UserID = 100, you will update both records 1 and 2. You will need to do multipl einsert statements. You can do this inside a stored procedure that you pass paramaters to (ie. parameter 1 is the message and parameter 2 is a comma seperated list of user ids). If you are not comfortable with stored procedures, you will need to construct and execute multiple insert statements in your code. Don't forget to use a transaction in case of failure.|||

Hi;

I guess I'm a little bit confused:) Could you explain me more deeply? I think I'm ok with stored procedures but what should this stored procedure include?

don't you think if J's solution works? I mean why shloud it update both records?

Thanks

|||

In your example table structure you have the same userID for 2 first records so f you do update for userID=100 both records will be updated. If you would like to do it for specific one you have to use ID column to select only one record. It was mistake or you can have two entries for the same userID in your table?

Thanks

|||

Oh i c;

Thanks, I will actually insert a new row I'm not gonna update so problem solved thanks...

Thanks to both masters;)

|||Here is an article on how to write a stored proc to take a comma seperated value (CSV) list into a stored proc. You should be able to adapt this for your own needs.