Q: SQL Error 512 while making sql job I am getting this error with the SQL below:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Does someone know how I can solve it?
 use character

 DECLARE @guild_codex varchar(25)
 DECLARE @character_name0 varchar(40)
 DECLARE @user_no0 varchar (25), @id varchar (25)
 DECLARE @user_no varchar (25), @group_id varchar (25), @amount varchar (25)
 DECLARE @free_amount varchar(25), @2mx_Leader varchar(3), @2mx_member varchar (3)

 SET @2mx_Leader = 700 SET @2mx_member = 500 SET @id = (SELECT id from
 [PC-ID].[Cash].[dbo].[user_cash] where free_amount LIKE 0) SET
 @user_no = (SELECT user_no from [PC-ID].[Cash].[dbo].[user_cash]
 where free_amount LIKE 0) SET @group_id = (SELECT group_id from
 [PC-ID].[Cash].[dbo].[user_cash] where free_amount LIKE 0) SET
 @amount =  (SELECT amount from [PC-ID].[Cash].[dbo].[user_cash]
 where free_amount LIKE 0) SET @free_amount =  (SELECT free_amount from
 [PC-ID].[Cash].[dbo].[user_cash] where free_amount LIKE 0) SET
 @guild_codex = (SELECT guild_code from siege_info where siege_tag LIKE'Y')

 SET @character_name0 = (SELECT character_name  from guild_char_info
 where guild_code LIKE @guild_codex and peerage_code LIKE 0) SET
 @user_no0 = (SELECT user_no from user_character where character_name
 LIKE @character_name0)   
 use cash   
 UPDATE user_cash SET
 amount=amount+@2mx_Leader WHERE user_no = @user_no0


A: Multiple issues with your SQL
To assign values for multiple variables, selecting from the same table, with the same where clause, you are making multiple trips to the DB, while it can be done in one single call, like this:
   SELECT
        @id = id,
        @user_no = user_no,
        @group_id = group_id,
        @amount = amount,
        @free_amount = free_amount
    FROM [PC-ID].[Cash].[dbo].[user_cash]
    WHERE free_amount LIKE 0

You are using LIKE, which could return multiple rows of data, as stated in your error message. Try using = if you can. Alternately, try executing the Select statements responsible for populating your variables to see if more than one row of data is returned.
Raj
