How to route query variable to object/property variable?

Welcome Forums General PowerShell Q&A How to route query variable to object/property variable?

Viewing 3 reply threads
  • Author
    Posts
    • #226329
      Participant
      Topics: 41
      Replies: 113
      Points: 647
      Rank: Major Contributor

      Given the following query which creates statement to recreate foreign key constraint, it prints the result into  @cmd variable, however, I can’t figure out how to route such variables set in a SQL query to a PowerShell variable…

      [/crayon]

      How do I accomplish this (  ...| Select ["@cmd"].Value;)?

      related

    • #226374
      Senior Moderator
      Topics: 9
      Replies: 1309
      Points: 4,783
      Helping Hand
      Rank: Community Hero

      You cannot use Select-Object cmdlet here. You may explore the members of $SqlCmd object once the query is executed.

      Do a

      Then there should be some property which shows the output of the query, if you can output @cmd value from the query itself.

      Note: I didn’t use SQL connection objects using PowerShell much.

      • This reply was modified 4 months, 2 weeks ago by kvprasoon. Reason: post correction
    • #226416
      Participant
      Topics: 13
      Replies: 1758
      Points: 3,153
      Helping Hand
      Rank: Community Hero

      Just return it in a Select and then you can capture it like an other Select statement:

    • #226479
      Participant
      Topics: 41
      Replies: 113
      Points: 647
      Rank: Major Contributor

      Just return it in a Select and then you can capture it like an other Select statement:

      PowerShell
      7 lines

      <textarea class=”ace_text-input” style=”opacity: 0; height: 17.9048px; width: 7.2381px; left: 45px; top: 0px;” spellcheck=”false” wrap=”off”></textarea>

      1
      2
      3
      4
      5
      6
      7
      CLOSE cursor_fkeys
      DEALLOCATE cursor_fkeys
      SELECT @cmd As Command
      | Select Command
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      Oh I didnt realize I can just select in sql. I thought anytime you select, has to be followed by FROM, interesting…

Viewing 3 reply threads
  • The topic ‘How to route query variable to object/property variable?’ is closed to new replies.