4

In my sql server 12.0 I have created a sequence:

CREATE SEQUENCE [dbo].[SESSIONI_dv_seq] 
 AS [bigint]
 START WITH 1
 INCREMENT BY 1
 MINVALUE -9223372036854775808
 MAXVALUE 9223372036854775807
 CYCLE 
 CACHE; 

sql server management studio works perfectly:

select Next value for  dbo.SESSIONI_dv_seq 

return the correct value.

At this point, in a powershell script I want to obtain a new sequence value using invoke-sqlcmd

$DataSet = Invoke-Sqlcmd -Database "alglogistica" -Query "SELECT SESSIONI_dv_seq_value=next value for dbo.sessioni_dv_seq;" -ServerInstance  "10.81.104.185\SQL14"

This statement doesn't work (without no error returned by the script).

I have tried other selects in the query and these work perfectly.

1 Answer 1

1

Something like this?

$result = Invoke-SQLCmd -Database alglogistica `
    -query "SELECT next value for dbo.sessioni_dv_seq as SESSIONI_dv_seq_value" `
    -serverinstance  "10.81.104.185\SQL14"
$id = $result.SESSIONI_dv_seq_value
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.